private void sample(){
int FRAME_BYTES=326;
int FRAMESMAX=36;
String subFolder="media";
String mediafileName="sample.mp4";
MediaMetadataRetriever mediaMetadata=new MediaMetadataRetriever();
try{
AssetFileDescriptor afd=getApplicationContext().getAssets().openFd(subFolder+File.separator+mediaFileName);
;
mediaMetadata.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
Bitmap frame=null;
for(int currentFrame=0;currentFrame<FRAMESMAX; currentFrame++){
if(currentFrame<=0){
frame = mediaMetadata.getFrameAtTime();
}else{
frame = mediaMetadata.getFrameAtTime(FRAME_BYTES*currentFrame*1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC );
//currentFrame++;
}
// do some thing with frame
}
}catch(Exception e){
Log.i(TAG, " unable to get file descriptor of the frame"+e.toString());
}
}
}
我能够在模拟器和其他设备上从 mp4 媒体文件中读取帧,但三星 Galaxy S III 抛出错误并指出
MediaMetadataRetriever getFrameAttime failed to retrieve video frames
.
对此有任何意见吗?