1
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