android获取视频头一帧,music信息

来源:互联网 发布:soap和json 编辑:程序博客网 时间:2024/06/07 03:43
1、Video对于视频,取第一帧作为缩略图,也就是怎样从filePath得到一个Bitmap对象。 private Bitmap createVideoThumbnail(String filePath) {        Bitmap bitmap = null;        MediaMetadataRetriever retriever = new MediaMetadataRetriever();        try {            retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY);            retriever.setDataSource(filePath);            bitmap = retriever.captureFrame();        } catch(IllegalArgumentException ex) {            // Assume this is a corrupt video file        } catch (RuntimeException ex) {            // Assume this is a corrupt video file.        } finally {            try {                retriever.release();            } catch (RuntimeException ex) {                // Ignore failures while cleaning up.            }        }        return bitmap;    }Android提供了MediaMetadataRetriever,由JNI(media_jni)实现。看得出MediaMetadataRetriever主要有两个功能:MODE_GET_METADATA_ONLY和MODE_CAPTURE_FRAME_ONLY这里设mode为MODE_CAPTURE_FRAME_ONLY,调用captureFrame取得一帧。另外还有两个方法可以用:extractMetadata 提取文件信息,ARTIST、DATE、YEAR、DURATION、RATING、FRAME_RATE、VIDEO_FORMAT和extractAlbumArt 提取专辑信息,这个下面的音乐文件可以用到。2、Music对于音乐,取得AlbumImage作为缩略图,还是用MediaMetadataRetriever private Bitmap createAlbumThumbnail(String filePath) {        Bitmap bitmap = null;        MediaMetadataRetriever retriever = new MediaMetadataRetriever();        try {            retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY);            retriever.setDataSource(filePath);            byte[] art = retriever.extractAlbumArt();            bitmap = BitmapFactory.decodeByteArray(art, 0, art.length);        } catch(IllegalArgumentException ex) {        } catch (RuntimeException ex) {        } finally {            try {                retriever.release();            } catch (RuntimeException ex) {                // Ignore failures while cleaning up.            }        }        return bitmap;    }retriever.extractAlbumArt()得到的是byte数组,还需要一步用BitmapFactory编码得到Bitmap对象。3、Image图片就很简单了         Bitmap bm = null;        Options op = new Options();        op.inSampleSize = inSampleSize;        op.inJustDecodeBounds = false;        bm = BitmapFactory.decodeFile(mFile.getPath(), op);复制代码能直接得到Bitmap对象,把图片缩小到合适大小就OK。同样上面的Video和Music,retrive到Bitmap后也需要缩小处理。
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 水养绣球花蔫了怎么办 鲜切绣球花蔫了怎么办 崩坏2仓库满了怎么办 dnf88级没任务了怎么办 0号柴油冻住了怎么办 不小心喝了生水怎么办 不小心吃了蟑螂怎么办 以租代购还不起怎么办 孩子被教官打了怎么办 三岁宝宝叛逆期怎么办 三岁宝宝很叛逆怎么办 孩子不听话怎么办有什么方法呢 打了三岁的宝宝怎么办 2岁半宝宝不听话怎么办 心里素质不好容易紧张怎么办 孩子二年级成绩差怎么办 遇到素质低的人怎么办 孩子上课注意力不集中怎么办 素质报告册丢了怎么办 潞城镇剩下5个村怎么办 高三复读生学籍怎么办 被检精子总数少怎么办 前向运动精子17%怎么办 精子形态正常率1怎么办 精子形态正常率2怎么办 精子头部畸形率高怎么办 椎底动脉供血不足怎么办 颈椎动脉供血不足怎么办 颈椎病引起头晕脑供血不足怎么办 淘宝店被释放了怎么办 被枣蝎子蛰了怎么办 六角螺丝拧花了怎么办 苹果螺丝滑丝了怎么办 六角螺帽拧花了怎么办 六角螺母拧花了怎么办 内六角螺丝滑丝怎么办 十字螺丝拧花了怎么办 梅花螺丝滑丝了怎么办 螺丝孔道滑丝了,怎么办 锅把铆钉松啦怎么办 膨胀螺丝孔大了怎么办