我发现了几个相关问题,但找不到我的具体问题的答案。
我试图发起视频活动,播放下载到SD卡的视频。它会抛出一个错误,说'#34;无法播放此视频"。当我在没有应用程序的情况下启动视频时它可以正常播放。
我在这里创建活动:
VideoView mVideoView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);
Intent intent = getIntent();
String url = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
setJsonData(url);
Log.d("URL VID",url);
Uri uri = Uri.parse(url); //Declare your url here.
mVideoView = (VideoView) findViewById(R.id.videoview);
mVideoView.setVideoURI(uri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(mVideoView);
mVideoView.setMediaController(vidControl);
mVideoView.requestFocus();
mVideoView.start();
}
当我这样做时,在尝试启动视频后出现此错误:
06-19 16:57:24.921 26033-26033/com.csform.android.uiapptemplate W/VideoView: Unable to open content: /storage/emulated/0/Nokia%20AirFrame.mp4
java.io.IOException: setDataSource failed.
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1120)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1066)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1003)
at android.widget.VideoView.openVideo(VideoView.java:437)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:742)
at android.view.SurfaceView.updateWindow(SurfaceView.java:730)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:211)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2420)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1324)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6712)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
at android.view.Choreographer.doCallbacks(Choreographer.java:696)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
我的权限设置如下:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
答案 0 :(得分:0)
mVideoView.setVideoURI(uri);
方法需要由mVideoView.setVideoPath(uri);
方法替换。此处uri
指定SDCARD
上的视频文件的路径。
setVideoURI
加载视频时, SDCARD
无效,您必须使用setVideoPath
。 setVideoURI
仅适用于来自互联网的视频流。
答案 1 :(得分:0)
这似乎是一个文件名问题。我更改了名称,因此它不再有空格或大写字符,错误消失了,我可以播放视频。