Android MediaPlayer 从 PHP 重定向流式传输不起作用!
我工作的公司正在开发一个 Android 应用程序,可以播放网络上 URL 的视频文件。这 视频 URL 是 PHP 脚本的一个参数,该脚本对其进行正确编码并重定向到编码视频,如下所示:
header('Content-Type: video/'.$format);
header('Location:'.$output_video);
其中 $output_video
是编码视频的 URL(如果我们在浏览器),$format
是视频格式。
但是当我尝试执行 MediaPlayerDemo_Video 从使用流模式的 API 演示中,我收到如下错误:
MediaPlayer Command PLAYER INIT completed with an error or info PVMFErrCorrupt
MediaPlayer error (1. -10)
MediaPlayer Error (1.-10)
如果我们在 PHP 脚本中对 URL 和格式进行硬编码,它也不起作用,但会出现不同的错误:
MediaPlayer info/warning (1. 28)
MediaPlayer Info (1 .28)
有人有吗关于如何解决这个问题的想法?
提前致谢!
The company I work for is developing an Android App that plays a video file from a URL on web. The
video URL is a parameter for a PHP script that encode it properly and redirects to the encoded video as shown below:
header('Content-Type: video/'.$format);
header('Location:'.$output_video);
Where $output_video
is the URL to the encoded video (it works if we use this URL in the browser) and $format
is the video format.
But when I try executing the MediaPlayerDemo_Video from the API Demos using the streaming mode, I get an error like this:
MediaPlayer Command PLAYER INIT completed with an error or info PVMFErrCorrupt
MediaPlayer error (1. -10)
MediaPlayer Error (1.-10)
If we hard-code the URL and format in the PHP script, it also does not work out, but with a different error:
MediaPlayer info/warning (1. 28)
MediaPlayer Info (1 .28)
Does anyone have an idea on how to workaround this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了同样的问题。结果 android MediaPlayer 无法处理重定向,因此您必须找到 php 脚本将您重定向到的位置,并按照 Jeorgesys 的解释为其提供 rtsp URL。
我能够通过执行 HttpGet 并且不遵循任何重定向,然后从“位置”Http 标头中提取 rtsp url 来解决。如果您有多个重定向,则会遇到更多麻烦,但幸运的是,就我而言,我只需要担心单个重定向。
I encountered this same problem. Turns out the android MediaPlayer won't handle redirects, so you have to find where the php script is redirecting you and give it the rtsp URL as Jeorgesys explained.
I was able to solve by performing a HttpGet and NOT following any redirects, then pulling the rtsp url from the 'Location' Http header. If you have multiple redirects, you'll have a little more trouble, but luckily in my case I only have to worry about a single redirect.
响应是您尝试在 MediaPlayer 中流式传输什么文件,您的 URL 必须类似于 ::
(尝试使用此网址)
使用 rtsp 协议 以及具有正确 Android 支持的编解码器 。
the response is what file are you tryin to stream in your MediaPlayer, your URL must be for example something like ::
(try with this URL)
using the rtsp protocol and a .3gp video file with the correct codecs supported for android .
我改编了 Mark 的答案以使用最新的 Apache HttpComponents:
I adapted Mark's answer to use up-to-date Apache HttpComponents:
这是一个简单的例子
Here is a simple example
php代码:
php code: