我正在使用类getFrameAtTime()
方法MediaMetadataRetriever
来获取位于视频(mp4)中特定时间的帧。当视频分辨率较低时,例如 480 x 270,这可以正常工作。但如果我使用同一视频的高清版本 (1280 x 720),则会出现错误。有什么出路吗?
日志猫:
06-11 08:24:45.714: D/dalvikvm(511): GC_EXTERNAL_ALLOC 释放 41K,53% 释放 2550K/5379K,外部 1625K/2137K,暂停 120ms
06-11 08:24:46.974: E/MediaMetadataRetrieverJNI(511): getFrameAtTime: videoFrame 是一个空指针
代码是这样的:
package com.asin.amit;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class AsinActivity extends Activity {
/** Called when the activity is first created. */
private MediaMetadataRetriever mediam;
private Bitmap bmp;
private int g;
private ImageView myImageView;
private TextView tv ;
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mediam = new MediaMetadataRetriever();
String str= "/sdcard/DCIM/wdc.mp4";
mediam.setDataSource(str);
} catch (Exception e) {
// handle any errors
Log.e("HelloWorld", "1", e); // log the error
// Also let the user know something went wrong
Toast.makeText(
getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
try {
bmp=mediam.getFrameAtTime();
} catch (Exception e) {
// handle any errors
Log.e("HelloWorld", "2", e); // log the error
// Also let the user know something went wrong
Toast.makeText(
getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}