与Android的MediaPlayer在SDK 8流 [英] Streaming with Android MediaPlayer in SDK 8

查看:205
本文介绍了与Android的MediaPlayer在SDK 8流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SDK 8级(升级Froyo)公司推出的原生能力的MediaPlayer的连接到数据流源,如Shoutcast的。 previous SDK版本能够做的解决方法,如在设备上运行的本地代理(见 NPR )。

SDK level 8 (Froyo) has introduced the native capability for the MediaPlayer to connect to a streaming source, like Shoutcast. Previous SDK versions were able to do workarounds, such as run a local proxy on the device (see NPR).

我采取了同样的方法,NPR和正在使用StreamProxy。然而,NPR首先检查当前运行的SDK是小于8。如果是这样,它使用代理。否则,它直接连接

I took the same approach as NPR and am using a StreamProxy. However, NPR first checks if the currently running SDK is less than 8. If so, it uses the proxy. Otherwise, it connects directly.

我的StreamProxy请求的元数据来自SHOUTcast服务器,所以它不只是路线从Shoutcast的数据为我的客户。相反,它解析出元数据,并使用它相应,并且仅路由音乐数据

My StreamProxy requests metadata from the Shoutcast server, so it does not simply route the data from Shoutcast to my client. Instead, it parses out metadata and uses it accordingly, and only routes the music data.

当试图用StreamProxy在SDK 8级以上,在MediaPlayer未能prepare。我StreamProxy接收连接,并接受它,而是成功地写出了状态栏和标题给客户端后,下次再写产生 java.net.SocketException异常:连接复位 。这将导致在客户端的媒体播放器抛出错误(1,-1007)

When trying to use the StreamProxy at SDK level 8 or above, the MediaPlayer fails to prepare. My StreamProxy receives the connection and accepts it, but after successfully writing out the status line and headers to the client, the next write produces java.net.SocketException: Connection reset by peer. This results in the client's mediaplayer throwing an Error(1,-1007).

我试图找出为什么在MediaPlayer无法连接到我的本地代理。它应该是相同的连接到原始来源没有元数据,其中确实的工作。我转发的所有头从外部源,通过我的代理,其中包括内容类型。

I am trying to figure out why the MediaPlayer is unable to connect to my local proxy. It should be the same as connecting to the original source without the metadata, which does work. I am forwarding on all headers from the external source, through my proxy, which includes content-type.

我将继续寻找到它,但我觉得我在一个死胡同。让我知道如果需要更多的细节。

I will continue looking into it, but I feel like I'm at a dead-end. Let me know if more details are needed.

推荐答案

编辑:好吧,我相信现在我有答案

Ok I now believe I have the answer!

Stagefright是严格的,当涉及到行结束在HTTP头;他们必须CR,LF并不仅仅是LF已经先前的工作。

Stagefright is strict when it comes to line-endings in the HTTP-header; They have to be CR,LF and not just LF which has worked earlier.

所以,如果你建立你自己的头,更换任何\ N\ r \ N,然后你应该罚款。

So if you build your own headers, replace any "\n" with "\r\n" and you should be fine.

(如果你想检查自己这一点,看看 receive_line()媒体/ libstagefright / HTTPStream.cpp

(If you want to check this for yourself, look at receive_line() in media/libstagefright/HTTPStream.cpp)

我现在可以流Shoutcast的元数据在2.2 / Stagefright手机...

I can now stream shoutcast with Metadata on 2.2/Stagefright phones...

...

我已经运行到了同样的问题;

I have been running into the same problem;

首先,我试图写入流数据为固定长度文件和包装 - 和与setLooping(真)播放。这会导致故障时,MP3的循环,即使我解压整个MP3帧,并试图垫不均匀字节到底既0xFF的和×00。这可能仍是一个可接受的解决方案,如果你有一个足够大的文件。

First I tried writing the streamed data to a fixed length file and wrapping - and playing it with setLooping(true). This causes glitches when the MP3 loops, even though I extract whole MP3 frames and tried to pad the uneven bytes at the end with both 0xff and 0x00. This might still be an acceptable solution if you have a big enough file.

然后我做代理的东西的作品在我的三星Galaxy S(V2.2),但不是在模拟器中,显然不是在欲望(不工作=错误-1007如上所述)。 一个提示可能是Galaxy S的媒体播放器要求HTTP1.0,而这是在模拟器1.1。

Then I did the proxy thing which works on my Samsung Galaxy S (v2.2) but not in the emulator and apparently not on the Desire (Not working = Error -1007 as mentioned above). One hint may be that the Galaxy S Mediaplayer asks for HTTP1.0, while it is 1.1 in the emulator.

的蛮力方法是打开并联2个流,从一个读出元数据,并从其他流;)

The brute-force method would be to open 2 streams in parallel, reading meta-data from one and streaming from the other ;)

反正,我也想听到的话,任何人有过更多的运气...

Anyway, I also want to hear if anyone else has had more luck...

这篇关于与Android的MediaPlayer在SDK 8流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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