VideoView 错误,当我通过 url 加载视频时
Posted
技术标签:
【中文标题】VideoView 错误,当我通过 url 加载视频时【英文标题】:VideoView error, when I load video by url 【发布时间】:2020-10-16 12:52:06 【问题描述】: val uri = Uri.parse("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
videoView.setVideoURI(uri)
videoView.pause()
videoView.seekTo(1)
这是我的代码。代码非常简单,它可以运行,我们可以播放和观看视频,但在日志中我看到了
W/MediaPlayer: Couldn't open https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4: java.io.FileNotFoundException: No content provider: https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@806a87): Cookies: null
V/MediaHTTPService: makeHTTPConnection: CookieHandler (java.net.CookieManager@8633fd2) exists.
我该如何解决?
【问题讨论】:
【参考方案1】:您的代码不完整:
private void playVideo()
VideoView videoview = (VideoView) findViewById(R.id.playvideo);
Uri uri = Uri.parse("https://commondatastorage.googleapis.com/gtv-videos-
bucket/sample/BigBuckBunny.mp4")
videoview.setVideoURI(uri);
videoview.setMediaController(new MediaController(this));
videoview.setOnErrorListener(new OnErrorListener()
@Override
public boolean onError(MediaPlayer mp, int what, int extra)
progress.setVisibility(View.GONE);
finish();
return false;
);
videoview.setOnPreparedListener(new OnPreparedListener()
@Override
public void onPrepared(MediaPlayer mp)
progress.setVisibility(View.GONE);
mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener()
@Override
public void onVideoSizeChanged(MediaPlayer mp, int arg1,int arg2)
progress.setVisibility(View.GONE);
);
);
videoview.setOnCompletionListener(new OnCompletionListener()
@Override
public void onCompletion(MediaPlayer mp)
finish();
);
videoview.requestFocus();
videoview.start();
【讨论】:
好的,感谢您提供更完整的代码,但它是如何解决问题的?以上是关于VideoView 错误,当我通过 url 加载视频时的主要内容,如果未能解决你的问题,请参考以下文章
“无法播放此视频”错误使用带有 VideoView 和 Mediacontroller 的 URL
Android:尝试通过 AsyncTask 加载 videoview 时出现 NullPointerException [重复]
Android MediaPlayer 错误 (1, -2147483648)