Android媒体录制器准备失败

时间:2012-03-17 16:44:40

标签: android video-streaming android-camera android-mediarecorder

sock = new Socket();
sock.connect(new InetSocketAddress(addr, port), 2000);
if(!sock.isConnected()) return false;

file = ParcelFileDescriptor.fromSocket(sock);

camera = Camera.open();
if(camera == null) return false;
camera.unlock();

recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(file.getFileDescriptor());
recorder.setPreviewDisplay(preview.getHolder().getSurface());// SurfaceView preview

recorder.prepare();

清单:

uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"
uses-permission android:name="android.permission.CAMERA"
uses-permission android:name="android.permission.RECORD_AUDIO"
uses-feature android:name="android.hardware.camera"

我总是收到错误prepare failed: -1

此代码适用于android> 2.2,在三星Galaxy S2上测试

1 个答案:

答案 0 :(得分:0)

删除核心 -

recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

并设置它 -

recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);