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..");
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()
.