0
我有這個問題讓我的adnroid程序工作。我有這個作爲我record.java代碼Android的記錄視頻
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class record extends Activity{
MediaRecorder recorder;
SurfaceHolder holder;
boolean recording = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.view);
SurfaceView cameraView = (SurfaceView) findViewById(R.id.sView);
holder = cameraView.getHolder();
holder.addCallback((Callback) this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
cameraView.setClickable(true);
cameraView.setOnClickListener((OnClickListener) this);
}
private void initRecorder() {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mpg");
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setMaxDuration(60000); // 60 seconds
recorder.setMaxFileSize(100000000);// Approximately 10 megabytes
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
}
private void prepareRecorder() {
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
public void onClick(View v) {
if (recording) {
recorder.stop();
recording = false;
// Let's initRecorder so we can record again
initRecorder();
prepareRecorder();
} else {
recording = true;
recorder.start();
}
}
public void surfaceCreated(SurfaceHolder holder) {
prepareRecorder();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
if (recording) {
recorder.stop();
recording = false;
}
recorder.release();
finish();
}
我的Android清單看起來是這樣的,以及
<activity android:name=".record"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.apapa.ttt.RECORD" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.record_audio"/>
如何過,當我運行這段代碼總是帶來出現錯誤「應用程序意外停止,請再試一次」我真的很困惑我在這裏做錯了什麼,因爲我認爲我的每一步都是正確的。任何幫助都感激不盡。
請從logcat – MByD 2011-05-25 15:40:54
添加錯誤日誌,從哪裏得到「android.permission.RECORD_VIDEO」? – SERPRO 2011-08-17 13:53:59
[我如何在Android上捕捉視頻錄製?](http://stackoverflow.com/questions/1817742/how-can-i-capture-a-video-recording-on-android) – Ewoks 2014-11-20 16:45:35