MediaPlayer() audio stuttering(android)

混江龙づ霸主 提交于 2019-12-20 06:15:04

问题


I am using the MediaPlayer function to stream a live audio stream from a remote server, in my android app. But the audio is choppy and stuttering. The problem is not my internet as the feed plays perfectly when I play it on the computer. What could be the problem?*Note: the streams are live. This is the code I'm using:

MediaPlayer mp = new MediaPlayer();
    try{
    mp.setDataSource("http://radiotool:80/feed 342.mp3");//hardcoded for testing purposes
    mp.prepare();
    mp.start();
    }
    catch(Exception e)
    {Log.d("Error came up man",", check the internet connection and stuff..");

回答1:


The stream you are linking to is not sending a large buffer of data at the beginning of the stream. Normally this is not a problem, as the client is responsible for determining the rate of playback, watching the data transfer rate, and managing a client-side buffer accordingly. That is why when I gave you a link to try that does use a large buffer, this wasn't a problem to play.

Basically, the audio dropouts are due to constant buffer underruns. To fix this, you need to increase the buffer size. It seems this isn't possible right now, but another method may be to manage the HTTP client yourself and proxy the data to the MediaPlayer. That link is quite old... hopefully someone has figured out how to do this another way since then. I am not an Android developer, so I cannot tell you for sure.

What I would do first is call mp.prepareAsync(), and wait 2 seconds after the MediaPlayer tells you that it is ready to start. I have a hunch that data will continue to buffer in the background until you actually call .start().



来源:https://stackoverflow.com/questions/15439895/mediaplayer-audio-stutteringandroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!