Android Studio - 视频应用程序崩溃 - Videoview& Mediaplayer - 无法播放录音

时间:2017-11-09 12:03:56

标签: java android video android-intent

我有一个应用程序,我使用按钮启动摄像机,意图录制视频。这工作正常,应用程序返回mainactivity。当返回mainactivity时,我希望最后录制的视频在VideoView中播放。此时我的问题就出现了。

我试图按照下面提供的链接说明,但显然不正确。

https://developer.android.com/training/camera/videobasics.html

Logcat说我需要使用Mediaplayer。有人可以帮我解决一些代码吗?

提前致谢!

11-09 12:43:12.894 27047-27047/com.example.t.videorecorder E/MediaPlayer[Native]: Unable to create media player
11-09 12:43:12.896 27047-27047/com.example.t.videorecorder W/VideoView: Unable to open content: content://media/external/video/media/33789
java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1061)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1050)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1004)
at android.widget.VideoView.openVideo(VideoView.java:353)
at android.widget.VideoView.access$2200(VideoView.java:72)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:664)
at android.view.SurfaceView.updateWindow(SurfaceView.java:579)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:238)
at android.view.View.dispatchWindowVisibilityChanged(View.java:8704)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1338)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1077)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5845)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5272)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

logcat的:

{{1}}

1 个答案:

答案 0 :(得分:1)

以下是包含媒体播放器的代码:

vW.setMediaController(new MediaController(this));
vW.requestFocus();
vW.start();

并在清单

中添加READ_EXTERNAL_STORAGE权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

在android marshmallow中转到设置然后app然后转到应用程序并在权限允许存储访问权限。