我想在Android应用程序中显示视频。我在谷歌搜索过,发现以下代码
VideoView videoView =(VideoView)findViewById(R.id.videoView);
String vidAddress =" https://docs.google.com/a/user.co.jp/file/d/something..private cookie / preview&#34 ;;
Uri videoUri = Uri.parse(vidAddress);
MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(的MediaController);
videoView.setVideoURI(VIDEOURI); videoView.start();
我已将上述代码放在onCreate活动方法中。
当我运行应用程序时出现错误"抱歉,此视频无法播放。"
日志显示如下
07-15 13:58:13.110: V/MediaPlayer-JNI(19546): native_setup
07-15 13:58:13.110: V/MediaPlayer(19546): constructor
07-15 13:58:13.125: V/MediaPlayer(19546): setListener
07-15 13:58:13.125: I/MediaPlayer(19546): path is null
07-15 13:58:13.125: D/MediaPlayer(19546): Couldn't open file on client side, trying server side
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer-JNI(19546): setAudioStreamType: 3
07-15 13:58:13.140: V/MediaPlayer(19546): MediaPlayer::setAudioStreamType
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer(19546): prepareAsync
07-15 13:58:16.810: V/MediaPlayer(19546): message received msg=100, ext1=1, ext2=-2147483648
07-15 13:58:16.810: E/MediaPlayer(19546): error (1, -2147483648)
07-15 13:58:16.810: V/MediaPlayer(19546): callback application
07-15 13:58:16.810: V/MediaPlayer(19546): back from callback
07-15 13:58:16.815: E/MediaPlayer(19546): Error (1,-2147483648)
07-15 13:58:16.815: D/VideoView(19546): Error: 1,-2147483648
我可以在浏览器上看到视频。
上传的视频文件类型为mpg,mp4和wmv
如果有人有解决方案,请提供帮助。
由于
编辑:经过一些工作后我才知道其中一个原因是Android 4.0.3版。上面提到的代码适用于样本网址 http://download.itcuties.com/teaser/itcuties-teaser-480.mp4 仅在4.2.2中。 来自Google文档网址的视频仍无效。我该怎么做才能在4.0.3上播放
答案 0 :(得分:1)
您解析为Uri的网址与VideoView不兼容,因为它只是一个用于在html中嵌入iframe的网址。请按此here获取解决方案。
答案 1 :(得分:0)
答案 2 :(得分:0)
您可以使用网络视图
String frameVideo = "<html><body>Video From YouTube<br><iframe width=\"420\"
height=\"315\" src=\"https://drive.google.com/file/d/VIDEO_ID/preview\"
frameborder=\"0\" allowfullscreen></iframe></body></html>";
WebView myWebView = (WebView) findViewById(R.id.mWebView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadData(frameVideo, "text/html", "utf-8");