简体   繁体   English

是否需要内容提供商才能将http视频流传输到android.widget.VideoView?

[英]Do I need a content provider to stream http video to android.widget.VideoView?

I have some odd behavior while trying out Android's VideoView widget. 试用Android的VideoView小部件时,我有一些奇怪的行为。 When I set the url programatically (scrapped from the Internet): 当我以编程方式设置网址(从互联网上删除)时:

val url = getURLOnline()
val video = Uri.parse(url)
videoView.setVideoURI(video)

I get the following error: 我收到以下错误:

MediaPlayer: Couldn't open "http://cdn.samplemediafile.xyz/thevideo.mp4": java.io.FileNotFoundException: No content provider: "http://cdn.samplemediafile.xyz/thevideo.mp4"
NuPlayer: onSetVideoSurface(0xa93b3000, no video decoder)
FileSource: Failed to open file '"http://cdn.samplemediafile.xyz/thevideo.mp4"'. (No such file or directory)

Funny thing is, when I hard-code the same URL it suddenly works fine! 有趣的是,当我对相同的URL进行硬编码时,它突然可以正常工作! So, it's not a codec problem. 因此,这不是编解码器问题。 Of course I tried other Videos, too. 当然,我也尝试了其他视频。 Same result, only hard-coded works. 结果相同,只有硬编码的作品。 Why is that? 这是为什么?

val video = Uri.parse("http://cdn.samplemediafile.xyz/thevideo.mp4")
videoView.setVideoURI(video)

Found it! 找到了! Silly coding mistake... 愚蠢的编码错误...

Failed to open file '"http://cdn.samplemediafile.xyz/thevideo.mp4"'
                     ^                                           ^

The URL comes back surrounded with quotation marks. URL返回,并用引号引起来。 Needed a fix in my scraping code. 需要修复我的抓取代码。 Video is playing fine now. 视频现在播放良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM