Android 2.2에서 실행중인 삼성 Galaxy 탭이 있습니다. 나는 오디오와 비디오를 별도로 녹음하는 간단한 프로그램을 개발했다. 그것은 내 갤럭시 탭에서 잘 작동하고있었습니다. 하지만, 안드로이드 2.3.3으로 업그레이드 한 후에 모든 것이 바뀌 었습니다. 내 코드는 그 순간부터 작동을 멈췄습니다. 레이아웃 목적으로 사용 내 XML 파일들이다MediaRecorder - 펌웨어 업그레이드 후 코드 작동이 중단되었습니다.
PID TAG MESSAGE
D 75 CameraHardwareSec MemoryHeapBase(fd(27), size(5760128), width(800), height(600))
E 75 AuthorDriver Command 13 completed with error -17
E 7169 MediaRecorder prepare failed: -17
W 7169 System.err java.io.IOException: prepare failed.
W 7169 System.err at android.media.MediaRecorder._prepare(Native Method)
W 7169 System.err at android.media.MediaRecorder.prepare(MediaRecorder.java:592)
W 7169 System.err at com.video.streamer.view.CameraPreview$2.run(CameraPreview.java:121)
W 7169 System.err at java.lang.Thread.run(Thread.java:1019)
E 7169 MediaRecorder start called in an invalid state: 0
W 7169 dalvikvm threadid=10: thread exiting with uncaught exception (group=0x40015578)
E 7169 AndroidRuntime FATAL EXCEPTION: Thread-11
E 7169 AndroidRuntime java.lang.IllegalStateException
E 7169 AndroidRuntime at android.media.MediaRecorder.start(Native Method)
E 7169 AndroidRuntime at com.video.streamer.view.CameraPreview$2.run(CameraPreview.java:127)
E 7169 AndroidRuntime at java.lang.Thread.run(Thread.java:1019)
W 118 ActivityManager Force finishing activity com.video.streamer.view/.CameraPreview
:
// import statements
public class CameraPreview extends Activity implements SurfaceHolder.Callback {
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;
Button recordButton;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView) findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control, null);
LayoutParams layoutParamsControl = new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
recordButton = (Button)viewControl.findViewById(R.id.start_recording);
recordButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startRecording();
}
});
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (previewing) {
camera.stopPreview();
previewing = false;
}
if (camera != null) {
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
}
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
private void startRecording() {
try {
stopPreview();
Thread video = new Thread(new Runnable() {
public void run() {
videoRecorder = new MediaRecorder();
videoRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
videoRecorder.setOutputFormat(2);
videoRecorder.setVideoEncodingBitRate(56 * 8 * 1024);
videoRecorder.setVideoSize(176, 144);
videoRecorder.setVideoFrameRate(12);
videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
videoRecorder.setOutputFile("/sdcard/video.m4e");
try {
videoRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
videoRecorder.start();
}
});
video.start();
Thread audio = new Thread(new Runnable() {
public void run() {
audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
audioRecorder.setOutputFile("/sdcard/audio.amr");
try {
audioRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
audioRecorder.start();
}
});
audio.start();
} catch (Exception e) {
Log.e("streamer", "Unable to start recording", e);
}
}
private void stopPreview() {
if (camera == null) {
throw new RuntimeException();
}
camera.stopPreview();
camera.release();
camera = null;
}
}
다음 로그 출력됩니다 : 여기에 행동 (:) 나를 위해)이 예상치를 보여주고 내 코드입니다. camera.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView
android:id="@+id/camerapreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
control.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<Button
android:id="@+id/start_recording"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" * Start Recording"
android:layout_gravity="right"
android:layout_margin="10px"
/>
</LinearLayout>
나는 AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
내가 roman10 사람의 블로그에서 가져온 비디오 녹화 예에 다음과 같은 권한 사용 : Android Video Recording API–Illustrated with an Example도 일하고 있었다 내 안드로이드 2.2. 그러나, 그것은 또한 나의 업 그레 이드 결과로 일하는 것을 멈췄다.
android 2.3.3으로 비디오를 녹화 할 때 누락 된 항목이 있습니까? 이 문제를 어떻게 해결할 수 있습니까?
나는 동일한 문제가 있습니다. – lukewm