Android 在某些设备中使用媒体播放器录制视频时启动失败-19
我正在尝试使用带有摄像机配置文件480P的媒体录像机录制480X640视频,但在某些设备中,当我按下开始录制时,它给我的启动失败-19Android 在某些设备中使用媒体播放器录制视频时启动失败-19,android,android-videoview,recording,android-mediarecorder,Android,Android Videoview,Recording,Android Mediarecorder,我正在尝试使用带有摄像机配置文件480P的媒体录像机录制480X640视频,但在某些设备中,当我按下开始录制时,它给我的启动失败-19 private void initRecorder() { if(recorder!=null) return; // to delete the previous mp4 file created File deletefile=new File(outputFileName!=null?outputFileName:"abc.m
private void initRecorder() {
if(recorder!=null) return;
// to delete the previous mp4 file created
File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
if(deletefile.exists())
deletefile.delete();
//Create Folder
File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
if(!folder.exists() )
{
folder.mkdirs();
}
File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4");
outputFileName= outFile.toString();
System.out.println("Filename "+outputFileName);
if(outFile.exists())
outFile.delete();
try{
//camera.stopPreview();
camera.unlock();
recorder=new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if(typ==1)
{
//sequence should not be change
//Setting the quality of front camera
recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
//To rotate the camera by 630 i.e 90 by default + 270=630
int rot=270;
recorder.setOrientationHint(rot);
}else //video settings for back camera
{
recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));
recorder.setOrientationHint(camera_orientation);
}
recorder.setMaxDuration(20000); //20 sec
recorder.setPreviewDisplay(holder.getSurface());
recorder.setOutputFile(outputFileName);
recorder.prepare();
Log.v(TAG,"MediaRecorder initilized");
}
catch(Exception e)
{
runOnUiThread(new Runnable(){
@Override
public void run(){
Toast.makeText(getApplicationContext(), "Unable to connect camera", Toast.LENGTH_SHORT).show();
}
});
Log.v(TAG,"MediaRecorder failed to initilized");
e.printStackTrace();
}
// beginRecording();
}
编辑:
private void initRecorder() {
if(recorder!=null) return;
// to delete the previous mp4 file created
File deletefile=new File(outputFileName!=null?outputFileName:"abc.mp4");
if(deletefile.exists())
deletefile.delete();
//Create Folder
File folder = new File(Environment.getExternalStorageDirectory()+"/Chance");
if(!folder.exists() )
{
folder.mkdirs();
}
File outFile= new File(folder.toString(),System.currentTimeMillis()+".mp4");
outputFileName= outFile.toString();
System.out.println("Filename "+outputFileName);
if(outFile.exists())
outFile.delete();
try{
//camera.stopPreview();
camera.unlock();
recorder=new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if(typ==1)
{
//sequence should not be change
//Setting the quality of front camera
if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_480P))
recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_480P));
else if(CamcorderProfile.hasProfile(1, CamcorderProfile.QUALITY_LOW))
{
Log.v(TAG,"MediaRecorder LOW QUALITY");
recorder.setProfile(CamcorderProfile.get(1,CamcorderProfile.QUALITY_LOW));
if(optimalVideoSize!=null)
recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
else
recorder.setVideoSize(640, 480);
}
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
//To rotate the camera by 630 i.e 90 by default + 270=630
int rot=270;
recorder.setOrientationHint(rot);
}else //video settings for back camera
{
//Setting the quality of front camera
if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_480P))
recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_480P));
else if(CamcorderProfile.hasProfile(0, CamcorderProfile.QUALITY_HIGH))
{
Log.v(TAG,"MediaRecorder HIGH QUALITY");
recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_HIGH));
if(optimalVideoSize!=null)
recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
else
recorder.setVideoSize(640, 480);
}
else
{
Log.v(TAG,"MediaRecorder LOW QUALITY");
recorder.setProfile(CamcorderProfile.get(0,CamcorderProfile.QUALITY_LOW));
if(optimalVideoSize!=null)
recorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
else
recorder.setVideoSize(640, 480);
}
recorder.setOrientationHint(camera_orientation);
}
recorder.setMaxDuration(20000); //20 sec
recorder.setPreviewDisplay(holder.getSurface());
recorder.setOutputFile(outputFileName);
recorder.prepare();
Log.v(TAG,"MediaRecorder initilized");
}
catch(Exception e)
{
runOnUiThread(new Runnable(){
@Override
public void run(){
Toast.makeText(getApplicationContext(), "Unable to connect camera", Toast.LENGTH_SHORT).show();
}
});
Log.v(TAG,"MediaRecorder failed to initilized");
e.printStackTrace();
}
// beginRecording();
}
相机不支持480P,那么我应该怎么做才能录制480 X 640
如果摄像机不支持480p的视频录制,则不能使用480p进行录制。以其他支持的分辨率记录<代码>低质量和
高质量
是唯一保证受支持的。如果您不喜欢QUALITY\u LOW
结果,并且QUALITY\u 480P
不可用,请在QUALITY\u HIGH
记录您的代码,查看是否支持480P,请使用hasProfile()
?我没有检查hasProfile(),即使我检查hasProfile并假设相机不支持480P,那么我应该如何录制480 X 640。我尝试使用低质量,它也可以工作,但它给我的171X144视频质量非常差。请检查我的编辑。我使用getsupportedvideosizes()获取支持的视频大小,并在此基础上设置视频的视频大小。它在我的手机上工作,但我仍然不确定它是否在每一部手机上都能工作。@ShashankAgarwal:我怀疑这个星球上是否有人知道什么代码在每一部手机上都能工作。:-)当然,我不能说它会不会。我没有尝试混合使用setProfile()
和setVideoSize()
,所以我不知道会发生什么,对不起。它现在使用的是相同的代码:),我不知道你为什么不使用我的应用程序回复我的twitter视频。我只是你的另一个粉丝。无论如何,再次感谢!