来自 HttpResponse 对象的 Android 视频流
我想播放 HttpResponse 对象中的视频内容。内容正在从流媒体服务器下载。
我的要求是创建一个到服务器的 HTTP POST 请求。请求包含视频的 URL、用户的用户名和密码,用于身份验证。
我想知道如何创建 HTTP POST 请求并播放/下载视频。
请提供一些提示、步骤/代码以继续。
谢谢,
I want to play video content from HttpResponse object. The content is downloading from a streaming sever.
My requirement is to create a HTTP POST request to the server. Request contains the URL of video, username and password of the user for authentication purpose.
I wish to know how can we create a HTTP POST request and play/download the video.
Kindly provide some hints, steps/code to proceed.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不是 100% 确定,但我认为由于格式存储视频元数据的方式,您无法流式传输大部分视频。这就是为什么 youtube 必须转换视频文件而不是仅仅以任何格式显示它们。
有一些协议封装了这些元数据并允许您流式传输任何视频(这就是 youtube mobile 所做的)。您应该看一下 RTSP:http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol
如果您在 videoView 中使用 rtsp 链接,它应该可以完美地传输视频。关键是你的问题是服务器而不是客户端相关。
作为练习,您可以从 m.youtube.com 获取 rtsp 链接,然后使用 setVideoPath 传递到 videoView,它应该可以工作。
如果无法更改服务器实现,那么您可能会遇到问题,我猜您的解决方案是:
1)自己下载并解码视频,您必须处理所有元数据并确保视频正常工作。理论上,你可以为 android 编译 ffmpeg 来帮助你,但我无法在网络选项打开的情况下将其编译为 android。这是很多工作。
2) 编写您自己的 RTSP 或其他流媒体协议的实现。在线程中下载视频,然后在设备中创建本地服务器以将该视频文件流式传输到 videoView 实例。我实际上已经在一个应用程序上进行了此操作。 Android 不支持客户端服务器使用的特定协议,我必须让它工作。我花了整整一个月的时间才完成这件事。我无法发布任何示例代码,因为它都是客户的,但如果您感兴趣,我可以为您提供一些进一步的信息。
无论哪种方式,如果您无法更改视频的服务器/格式,那么您应该做好大量工作的准备。
I am not 100% sure, but I think that you can't stream most of the video due to the way the format stores the meta data of the video. That's why you tube has to convert your video files instead of just showing them in any format.
There are protocols that encapsulate this metadata and allows you to stream any video (that's what youtube mobile does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol
If you use an rtsp link in a videoView it should stream the video flawlessly. The point is that your problem is server and not client related.
As an exercise you could grab an rtsp link from m.youtube.com and just pass to a videoView using setVideoPath and it should work.
If can't change the server implementation then you probably them I guess your solutions are:
1) Download and decode the video yourself, you would have to handle all the metadata and ensure that the video does work though. You could, theoretically, compile ffmpeg for android to help you with that, but I couldn't compile it to android with the network option on. That is a lot of work.
2) Write your own implementation of RTSP or other streaming protocol. Download the video in a thread and them create a local server in the device to stream that video file to a videoView instance. I actually have this working on an app. Android doesn't support the specific protocol that the client's servers use and I had to get it working. It took me a full month to do this. I can't post any example code because it's all the client's, but I could give you some further info on this if you are interested.
Either way, if you can't change the server/format of the video then you should prepare for a whole lot of work.
检查以下代码以在视频视图中显示 url http 或 rtsp。
现在,在调用您的videoview之前..只需获取
Now,因为您的要求不同,首先向您的服务器发出http post请求...获取所需的输入流..将该流作为mp4写入本地文件系统。然后你可以使用下面的代码来播放内容
check the below code for showing a url http or rtsp in Video View.
Now before invoking your videoview .. just get
Now since your requirements are different first make http post request to your server ... get the desired input stream.. write that stream as mp4 to your local file system. then you can use below code to play content
我尝试了这个,它对我有用:D 没有 rtsp 没有什么,只是一个带有 mp4 视频的 url,它就播放了!
I tried this and it worked for me :D no rtsp no nothing, just a url with a mp4 video and it played!
查看以下链接
http://www.softwarepassion。 com/android-series-get-post-and-multipart-post-requests/
http://w3mentor.com/learn/java/android-development/android-http-services/performa-a-http-post-request-with-the-httpclient-in-android/
用于流式传输, 我认为您必须下载完整文件,然后在视频播放器中显示它。
Look into following links
http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/
http://w3mentor.com/learn/java/android-development/android-http-services/performa-a-http-post-request-with-the-httpclient-in-android/
For streaming, I think you have to download the full file, and then show it in the video player.