做一个视频录制的东西,不知道为什么,surfaceCreated不会被调用
public class RecorderActivity extends Activity implements SurfaceHolder.Callback ,MediaRecorder.OnErrorListener,
MediaRecorder.OnInfoListener{
private MediaRecorder mMediaRecorder = null;
private boolean mMediaRecorderRecording = false;
private SurfaceView mSurfaceView = null;
private SurfaceHolder mSurfaceHolder = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 选择支持半透明模式,在有surfaceview的activity中使用。
getWindow().setFormat(PixelFormat.TRANSLUCENT);
// 去掉标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_recorder);
mSurfaceView = (SurfaceView) this.findViewById(R.id.surfaceView1);
SurfaceHolder holder = mSurfaceView.getHolder();
holder.addCallback(this);
//mSurfaceHolder= mSurfaceView.getHolder();
//mSurfaceHolder.addCallback(this);
initializeVideo();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// 将holder,这个holder为开始在oncreat里面取得的holder,将它赋给surfaceHolder
mSurfaceHolder = holder;
}
理论上,如果surfaceCreated调用了,mSurfaceHolder 一定不会是空的,而在initializeVideo()中使用时,mSurfaceHolder 为空,求教怎么破?
------解决方案--------------------
理论上,如果surfaceCreated调用了,mSurfaceHolder 一定不会是空的,而在initializeVideo()中使用时,mSurfaceHolder 为空,求教怎么破?
我也不会,帮你顶一下吧。。。
------解决方案--------------------
加上这一句试试吧
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);