Android MediaPlayer 准备时间过长 [英] Android MediaPlayer is preparing too long

查看:54
本文介绍了Android MediaPlayer 准备时间过长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在使用 MediaPlayer 播放常规 ShoutCast 流.代码很简单,带有 prepareAsync() 和一个用于开始播放的处理程序.虽然它与 DI.FM 或 ETN.FM (http://u10.di.fm:80/di_progressive) 之类的某些流完美配合,但对于其他流 (http://mp3.wpsu.org:8000/),它不会t 越过准备状态.也不会调用其他侦听器.

Hey, I'm using MediaPlayer to play a regular ShoutCast stream. The code is straightforward with prepareAsync() and a handler to start the playback. While it works flawlessly with some streams like DI.FM or ETN.FM (http://u10.di.fm:80/di_progressive), with others (http://mp3.wpsu.org:8000/) it won't go past the prepare state. No other listeners are called either.

//Uri streamUri = Uri.parse("http://u10.di.fm:80/di_progressive"); /* works */
Uri streamUri = Uri.parse("http://mp3.wpsu.org:8000/"); /* stuck on prepare state */
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
    public void onPrepared(MediaPlayer mp) {
        mp.start();
    }
});
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(this.getBaseContext(), streamUri);
mediaPlayer.prepareAsync();

感谢任何反馈!

推荐答案

我认为服务器端存在一些兼容性问题.这很奇怪,因为模拟器在我的情况下可以正常处理 - 只是在我的 Froyo Galaxy S 上不行,即使它是相同的 API 版本.

I think that there are some compatibility problems with the server end. This is rather strange since the emulator handles it ok in my case - just not on my Froyo Galaxy S, even though it is the same API version.

这可能是编解码器问题,http 流问题,我不知道.但是所有出现故障的服务器往往都是旧服务器,底部带有Copyright 1998 - 2004"......您可能认为不是最近或最新的.

It could be a codec issue, http streaming issue, I do not know. But all the servers that fail tend to be old ones, with "Copyright 1998 - 2004" at the bottom... Not exactly recent or up to date you would think.

一种潜在的解决方法(我还没有尝试过)是使用 StreamProxy,这也将使您的代码与 2.1 和可能的早期版本兼容.以额外的工作、额外的代码和毫无疑问的额外错误为代价......

One potential workaround (which I have not tried yet) would be to use the StreamProxy, which would also make your code compatible with 2.1 and possibly earlier versions too. At the cost of extra work, extra code, and without doubt extra bugs...

如果您不知道,还有另一个可能与 2.2 相关的播放器错误报告:基本的流式音频在 2.1 中有效,但不能在 2.2

In case you are not aware of it, there is another player bug report for 2.2 which may be relevant too: Basic streaming audio works in 2.1 but not in 2.2

这篇关于Android MediaPlayer 准备时间过长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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