如何在Android上使用MediaPlayer流式传输经过身份验证的内容 [英] How to stream authenticated content with MediaPlayer on Android

查看:87
本文介绍了如何在Android上使用MediaPlayer流式传输经过身份验证的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多帖子问关于SO的问题,但是似乎没有一个明确的答案(或者至少我喜欢一个答案!)

我已经在基本身份验证(用户名/密码)后面保护了内容-我可以使用各种HTTP下载语法很好地下载内容,但是对于我来说,我无法确定如何告诉媒体播放器对其进行流式传输(并提供身份验证).我看到一篇帖子暗示不可能,因为MediaPlayer都是本机代码,并且没有Authenticator之类的东西.

有很多示例,这些示例说明了如何首先下载到缓存的副本然后进行播放,但是....这样的糟透了(文件可能有100 MB的MB).我看到至少有一个建议,以小块形式下载它,然后启动&停止播放(重定向到新文件),但是这种情况也很糟糕,因为(我认为)会出现断断续续的情况(不过我还没有尝试过)

这时我最好的想法是开始下载到缓存文件,然后在足够"时开始播放,同时继续填充文件....我<希望> 可以正常工作(但同样,您还没有尝试过).

我缺少明显的东西吗?使所有各个部分几乎都能正常工作真是太痛苦了,我使自己深信必须有一种方法来本地传输受保护的内容(或者让它采用已经建立且合格的InputStream),但是似乎并不高兴. >

顺便说一句,我是Mac/iPhone人士,也是Android的新手,所以我仍在与Java学习作斗争....如果我遗漏了一些明显的东西,请原谅.

解决方案

如果您控制服务器,则一种选择可能是对其进行修改,以便可以选择在身份验证时为内容生成一个临时的随机URL,然后流的.流功能会接受包含脚本参数的URL吗?

要完全在电话上完成操作,另一种选择是用Java或本机代码编写一个简单的http代理(如服务器),然后在后台线程中运行它.您无需将媒体播放器指向服务器,而是将其指向自己的设备上代理.代理将在处理身份验证的同时将请求传递到远程服务器.

I've seen quite a few posts asking this question on SO but there doesn't seem to be a definitive answer (or at least an answer I like!)

I've got content protected behind basic auth (username/password) -- I can download it fine using the various HTTP download clases but for the life of me I can't sort out how to tell media player to stream it (and provide the authentication). I saw one post that suggested it wasn't possible since the MediaPlayer is all native code and doesn't things like the Authenticator.

There are plenty of examples of how to first download to a cached copy and then play that back but....That sort of sucks (and the files maybe 100's of MB's). I saw at least one proposal to download it in smalish chunks and then start & stop the playback (redirecting to the new file) but that sort of sucks also since there would (I presume) be a stutter (I haven't tried it though)

The best idea I have at this point is to start downloading to a cache file and then when it's 'full enough' start up playback while I continue to fill the file.... I hope that this works (but again, haven't tried it).

Am I missing something obvious? It's so painful to have all the various pieces almost working and I sort of convinced myself that there had to be a way to natively stream protected content (or have it take a already established & qualified InputStream) but it appears no joy.

BTW I'm a Mac/iPhone guy and a newb at Android so I'm still fighting a bit of Java learning.... Excuse me if I'm missing something obvious.

解决方案

If you control the server, one option might be to modify it so that there's an option to generate a temporary, random URL for the content upon authentication, and then stream that. Will the streaming functions accept a URL that includes script parameters?

To do things entirely on the phone, another option would be to write a trivial http proxy like server in either java or native code and run it in a background thread. Instead of pointing the media player at the server, you'd point it at your own on-device proxy. The proxy would pass requests through to the remote server, while handling authentication.

这篇关于如何在Android上使用MediaPlayer流式传输经过身份验证的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆