我在我的相機應用程序中使用內置的Android意圖進行視頻錄製。我的應用程序可以啓動相機應用程序和錄製視頻,但是當我單擊內置相機應用程序的停止按鈕時,我的應用程序崩潰,並且在檢查保存視頻的目錄時,錄製的視頻將存儲在目錄中。爲什麼我停止視頻錄製時,我的應用崩潰了?
這是我的代碼,請檢查它。
Button makeVideo = (Button) findViewById(R.id.makeVideo);
makeVideo.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
Uri fileUri = getOutputMediaFileUri(); // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the video file name
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri()
{
return Uri.fromFile(getOutputMediaFile());
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile()
{
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStorageDirectory().getPath(), "My Videos");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists())
{
if (!mediaStorageDir.mkdirs())
{
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator+ "VID_" + timeStamp + ".mp4");
return mediaFile;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
if (requestCode == REQUEST_VIDEO_CAPTURED)
{
uriVideo = data.getData();
}
}
}
這裏是我的logcat
你在彙編中有write_external_storage權限嗎? – Blackbelt
他應該有,因爲沒有安全例外 – 2013-10-26 08:13:20
嘗試此鏈接 [你的是這可能重複] [1] [1]:http://stackoverflow.com/questions/7846772/mysterious -nullpointerexception-after-the-built-in-camera-app-saves-my-video-pro?rq = 1 –