我想在Android应用中展示视频。我在谷歌上搜索了以下代码:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
String vidAddress = "https://docs.google.com/a/user.co.jp/file/d/something..private cookie/preview";
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上播放它?