我在我的相机应用程序中使用内置的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
答案 0 :(得分:0)
API无法处理您在
中提供的路径mediaFile = new File(mediaStorageDir.getPath() + File.separator+ "VID_" + timeStamp + ".mp4");
尝试:
mediaFile = new File(mediaStorageDir.getPath() + "VID_" + timeStamp + ".mp4");
也许它会解决它或做一个更简单的时间格式:
mediaFile = new File(mediaStorageDir.getPath() + File.separator+ "VID_temp.mp4");
答案 1 :(得分:0)
mediaFile = new File(mediaStorageDir.getPath() + File.separator+ "VID_" + timeStamp + ".mp4");
File.sepator
与系统有关。 File有一个构造函数,它接受两个参数:File和String:
mediaFile = new File(mediaStorageDir, "VID_" + timeStamp + ".mp4");