如何将 FileDescriptor 与 HTTP URL 结合使用
我希望这能够让 Android 的 MediaPlayer 使用身份验证从 URL 进行流式传输,但现在我不太确定。我可以毫无问题地从开放服务器流式传输(无需身份验证),但我没有看到任何方法告诉 MediaPlayer
使用基本身份验证,除非使用 FileDescriptor
论证有效吗?所以我尝试了这个,但收到以下错误:
IllegalArgumentException: Expected file scheme in URI http://www.myserver.com/music.mp3
我的代码看起来像这样:
File f = new File(new URL("http://www.myserver.com/music.mp3").toURI());
FileInputStream fis = new FileInputStream(f);
mediaplayer.SetDataSource(fis.getFD());
Is it right to say that a FileDescriptor
can only be used with local file://
URLs而不是普通的 http://
URL?如果是这样,是否有人对如何从需要使用 Android 的 MediaPlayer 进行身份验证的服务器进行流式传输有任何其他想法?
I was hoping this was going to work for getting Android's MediaPlayer
to stream from a URL using authentication, but now I'm not so sure. I have no problem getting it to stream from an open server (no authentication) but I don't see any way to tell MediaPlayer
to use basic authentication unless perhaps using the FileDescriptor
argument works? So I tried this but got the following error:
IllegalArgumentException: Expected file scheme in URI http://www.myserver.com/music.mp3
My code looks something like this:
File f = new File(new URL("http://www.myserver.com/music.mp3").toURI());
FileInputStream fis = new FileInputStream(f);
mediaplayer.SetDataSource(fis.getFD());
Is it correct to say that a FileDescriptor
can only be used with local file://
URLs and not normal http://
URLs? If so, does anyone have any other ideas on how to stream from a server that requires authentication using Android's MediaPlayer
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不正确的,Java 采用了 Unix 哲学“一切都是文件”和 javadoc 读取:
但是,
MediaPlayer
只能使用setDataSource(FileDescriptor)
也许你可以尝试这样的事情(未经测试)
No, that's incorrect, Java takes the Unix philosophy that "everything is a file" and the javadoc reads:
However, the
MediaPlayer
can only open seekable file descriptors withsetDataSource(FileDescriptor)
Maybe you can try something like this (untested)