我正在开发用于视频录制的自定义相机应用.录制的视频存储在SD卡上.
该代码适用于所有设备,除了T-Mobile S3(SGH-T999 android v 4.1.2),我得到’无法播放此视频’错误.我已经研究了很多这个问题,尝试改变参数但仍然无法解决.
该代码适用于所有设备,除了T-Mobile S3(SGH-T999 android v 4.1.2),我得到’无法播放此视频’错误.我已经研究了很多这个问题,尝试改变参数但仍然无法解决.
W/VideoView( 4490): Unable to open content: /storage/sdcard0/MyCameraApp/VID_20140807_130327.ogg W/VideoView( 4490): java.io.IOException: setDataSourceFD Failed.: status=0x80000000 W/VideoView( 4490): at android.media.MediaPlayer.setDataSource(Native Method) W/VideoView( 4490): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1204) W/VideoView( 4490): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1175) W/VideoView( 4490): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1121) W/VideoView( 4490): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:953) W/VideoView( 4490): at android.widget.VideoView.openVideo(VideoView.java:249) W/VideoView( 4490): at android.widget.VideoView.access$2000(VideoView.java:51) W/VideoView( 4490): at android.widget.VideoView$6.surfaceCreated(VideoView.java:492) W/VideoView( 4490): at android.view.SurfaceView.updateWindow(SurfaceView.java:609) W/VideoView( 4490): at android.view.SurfaceView.access$000(SurfaceView.java:86) W/VideoView( 4490): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:178) W/VideoView( 4490): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) W/VideoView( 4490): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1955) W/VideoView( 4490): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119) W/VideoView( 4490): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4553) W/VideoView( 4490): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) W/VideoView( 4490): at android.view.Choreographer.doCallbacks(Choreographer.java:555) W/VideoView( 4490): at android.view.Choreographer.doFrame(Choreographer.java:525) W/VideoView( 4490): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) W/VideoView( 4490): at android.os.Handler.handleCallback(Handler.java:615) W/VideoView( 4490): at android.os.Handler.dispatchMessage(Handler.java:92) W/VideoView( 4490): at android.os.Looper.loop(Looper.java:137) W/VideoView( 4490): at android.app.ActivityThread.main(ActivityThread.java:4950) W/VideoView( 4490): at java.lang.reflect.Method.invokeNative(Native Method) W/VideoView( 4490): at java.lang.reflect.Method.invoke(Method.java:511) W/VideoView( 4490): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004) W/VideoView( 4490): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) W/VideoView( 4490): at dalvik.system.NativeStart.main(Native Method) D/VideoView( 4490): Error: 1,0 V/MediaPlayerService( 187): Client(13) destructor pid = 4490 I/AudioSink( 187): +++ close I/AudioSink( 187): --- close V/AudioSink( 187): closeSession V/MediaPlayerService( 187): disconnect(13) from pid 4490
代码段.
CamcorderProfile camcorderProfile=CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); camcorderProfile.videoFrameWidth = width; camcorderProfile.videoFrameHeight = ht; camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.H264; camcorderProfile.audioCodec = MediaRecorder.AudioEncoder.AMR_NB; camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4; mMediaRecorder.setProfile(camcorderProfile); mMediaRecorder.setAudioEncoder(AudioEncoder.AMR_NB); mMediaRecorder.setOutputFormat(OutputFormat.MPEG_4); mMediaRecorder.setVideoEncoder(VideoEncoder.MPEG_4_SP); mMediaRecorder.setVideoSize(width,ht);
提前致谢.
解决方法
请注意您的测试设备的规格.您可以使用raw和mp4作为常用选项