用媒体记录器录制视频
|
我正在使用Media Recorder编写视频录制功能的代码。,但是它抛出Io异常,非法状态异常,我在Google中搜索了很多次,但是对此代码没有适当的解释,我的代码是
public class Simple extends Activity {
/** Called when the activity is first created. */
Button button,button2;
MediaRecorder recorder;
Camera camera;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button) findViewById(R.id.button1);
button2=(Button) findViewById(R.id.button2);
camera=Camera.open();
Camera.Parameters params = camera.getParameters();
camera.setParameters(params);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), \"Video Start\", Toast.LENGTH_LONG).show();
String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += \"/temp.3mp4\";
recorder=new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(10);
recorder.setVideoSize(200, 300);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setMaxDuration(50000);
recorder.setMaxFileSize(5000000);
recorder.setOutputFile(mFileName);
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), \"Video Stop\", Toast.LENGTH_LONG).show();
recorder.stop();
}
});
}
}
没有找到相关结果
已邀请:
1 个回复
贡炮逗握惫
这是预览类...