Android raw 目录下视频的缩略图的获取
以下代码用于获取 Android raw目录下视频文件的缩略图:
/**
* 获取 raw 下 指定视频文件的缩略图
* @param aVideoName
* @return
*/
private Drawable getThumbnail(String aVideoName)
{
Drawable ret = null;
int id = 0;
try
{
id = R.raw.class.getDeclaredField(aVideoName).getInt(this);
Uri videoURI = Uri.parse("android.resource://" + this.getPackageName() + "/" + id);
ret = getThumbnail(videoURI);
} catch ( IllegalAccessException aE )
{
aE.printStackTrace();
} catch ( NoSuchFieldException aE )
{
aE.printStackTrace();
}
return ret;
}
private Drawable getThumbnail(Uri aVideoUri)
{
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, aVideoUri);
Bitmap bitmap = retriever
.getFrameAtTime(1*1000*1000, MediaMetadataRetriever.OPTION_PREVIOUS_SYNC);
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
return drawable;
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
时间: 2017-07-05