最近我遇到了这个问题但没有任何线索。我想使用“mediarecorder”记录720P视频流并实时发送到服务器。这是我的代码:
try{
soc = new Socket(InetAddress.getByName(hostname), port);
} catch (UnknownHostException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
CamcorderProfile pProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
//pProfile.videoFrameWidth = 1280;
//pProfile.videoFrameWidth = 720;
recorder.setProfile(pProfile);
//recorder.setOutputFile(myRecAudioFile.getAbsolutePath());//保存路径
pfd = ParcelFileDescriptor.fromSocket(soc);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();
android API级别是17,当我启动媒体记录器时,程序将死一两秒钟。错误日志如下:
IMediaDeathNotifier- media server died
Camera - Camera server died
遇到类似问题的人能给我一些建议吗?
答案 0 :(得分:2)
我认为您需要为MediaRecorder
设置预览显示:
SurfaceView mySurfaceView = (SurfaceView) findViewById(R.id.my_surface_view);
Surface mySurface = camera.getHolder().getSurface();
recorder.setPreviewDisplay(mySurface);
显然,除非您设置了预览显示表面(ref),否则Android不允许您播放视频。