Android MediaPlayer 需要很长时间来准备和缓冲 [英] Android MediaPlayer takes long time to prepare and buffer

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

问题描述

我的应用程序需要很长时间来准备和缓冲音频流.我已经阅读了这个问题 为什么Android的MediaPlayer准备一些直播流播放需要这么长时间?,但只是说有人遇到过这个问题,并没有说明如何改进问题.

My application takes a long time to prepare and buffer an audio stream. I have read this question Why does it take so long for Android's MediaPlayer to prepare some live streams for playback?, however it just says people have experienced this issue, it does not state how to improve the problem.

我在所有版本的 Android 中都遇到过这种情况,测试范围为 2.2 - 4.1.2.

I am experiencing this in all versions of Android, tested from 2.2 - 4.1.2.

流采用适合移动和 3G 连接的比特率.相同的流在等效的 iOS 应用中开始缓冲所需的时间不到一秒钟.

The streams are in a suitable bit-rate for mobile and 3G connection. The same stream takes less than a second to start buffering in the equivalent iOS app.

有没有办法指定应该缓冲的时间量?我知道 Tune In 广播应用程序提供了这个功能( https://play.google.com/store/apps/details?id=tunein.player).

Is there a way to specify the amount of time that should be buffered? I know that the Tune In radio application offers this feature ( https://play.google.com/store/apps/details?id=tunein.player ).

谢谢.

我再次测试,发现它只发生在运行 Gingerbread 及更高版本 (>=2.3) 的设备上.我知道 Android 将底层框架从 OpenCore 更改为 StageFright.那么如何优化媒体框架呢?老款 HTC Wildfire 可以准备、流式传输和播放,这似乎是错误的,比全新的 HTC One X 和 Nexus 7 快 10 倍.

I've tested again and found that it only happens on devices running Gingerbread and above (>=2.3). I know that Android changed the underlying framework from OpenCore to StageFright. So how can I optimise the media framework? It just seems wrong that the old HTC Wildfire can prepare, stream and play, literally 10x faster than the brand new HTC One X and Nexus 7.

推荐答案

几个月来我一直在为这个问题而苦苦挣扎.最后我找到了解决方案.

I have struggled with this question for months. Finally i found the solution.

真正的问题在于 MediaPlayer 类的实现.特别是 MediaPlayer 缓冲数据的方式.这就是为什么解决方案是创建您自己的缓冲,将其保存到临时文件并将其提供给 MediaPlayer.

The real problem is in the implementation of the MediaPlayer class. Particularly with the way MediaPlayer buffers the data. This is why the solution is to create your own buffering, save it to a temp file and feed that to MediaPlayer.

本教程和源代码详细解释了如何操作.http://androidstreamingtut.blogspot.nl/2012/08/custom-progressive-audio-streaming-with.html

This tutorial and source code explain exactly how. http://androidstreamingtut.blogspot.nl/2012/08/custom-progressive-audio-streaming-with.html

通过修改此代码,可以轻松创建更好的流媒体播放器.

By adapting this code, it is easy to create a much better streaming player.

Google Developers 真的搞砸了.

这个答案相当陈旧.现在我建议不要使用 MediaPlayer 而是使用 ExoPlayer.它是可扩展的、稳定的并且可以播放多种不同类型的媒体.你可以在这里找到它:https://github.com/google/ExoPlayer/

EDIT : This answer is rather old. Nowdays i would recommend not using MediaPlayer and use ExoPlayer instead. It is extendable, stable and can play many different types of media. You can find it here: https://github.com/google/ExoPlayer/

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

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