Android 警告:摄像头出现故障
我使用以下代码调用已存在的摄影机:Android 警告:摄像头出现故障,android,video,camera,record,samsung-mobile,Android,Video,Camera,Record,Samsung Mobile,我使用以下代码调用已存在的摄影机: // New intent to Camera feature Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); Uri fileUri = Uri.fromFile((new File((new Date()).toString()))); // create a file to save the video intent.putExtra(MediaStore.EXTRA_OUTP
// New intent to Camera feature
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri fileUri = Uri.fromFile((new File((new Date()).toString()))); // create a file to save the video
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
// start the Video Capture Intent
startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
我可以拍摄照片,但无法录制视频,我收到错误警告:摄像头故障
我试着做一些相关的事情,但没有收到好的效果。(尽管重置了手机)
请告诉我如何解决这个问题
谢谢
p/s:设备-三星Galaxy Tab 7 2.2.1
编辑:
我使用以下代码接收响应,并响应结果resultCode==result\u cancelled
if (resultCode == RESULT_OK) {
// Video captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Video saved to:\n" +
data.getData(), Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the video capture
Toast.makeText(this, "User cancelled the video capture", Toast.LENGTH_SHORT).show();
} else {
// Video capture failed, advise user
Toast.makeText(this, "Warning : Camera failed", Toast.LENGTH_SHORT).show();
}
我将你的代码与你的代码进行了比较。唯一的区别是文件uri。您可以尝试使用Google的示例代码来获取文件uri:
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyCameraApp");
// 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;
if (type == MEDIA_TYPE_IMAGE){
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
} else if(type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
你为什么不检查一下意图是否真的回来了?与此类似,也检查此线程@Boris:I编辑了代码,请跟随您的评论。我还运行了第二个链接(项目),结果出现了黑屏@什么也没有发生。您必须创建新的活动,以便添加Surfaceholder和MediaRecorder类处理视频录制。您可以发布代码的示例项目,以便更轻松地进行尝试吗?如果我的设备尚未安装SD卡,会出现什么问题?我还是用这个功能好吗?至少你有间隔存储吧?该方法意味着您可以获取设备的公共目录。有些设备可能只有内部存储,但并非所有设备都像三星的设备那样有额外的SD卡插槽。所以这个方法可以很好地工作是的,至少我有内部存储。所以你的回答与我的错误无关。很抱歉