I use this code:
mediaPlayer.setDataSource("http://some online radio");
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepareAsync();
and onPrepared
method is:
if (mediaPlayer != null) {
mediaPlayer.start();
}
In general, the problem is: then i run this code, playback does not start right away, but about 10 seconds later. + some streams do not start at all, on the emulator it works a little better, than on the device, but still. It depends on concrete radio, some are better, other very bad.
I assume that the matter is in the preparation and buffering. It can be possible to make an InputStream
from this stream and write to some temporary file / buffer, and read/play this file in the MediaPlayer
, but how to implement it is, not yet clear .. Help please
If you just do mp.prepare
, and then mp.start
- the result is the same
On a PC in Chrome, all the radio streams that I tried to use immediately start playing
Sorry for my english, thank you.
It seems like audio bitrate might be the key here: https://stackoverflow.com/a/12850965/3454741. There is no easy way to get around this, it seems.
If the streaming does not start at all it might be due to some error, which you could catch using MediaPlayer.setOnErrorListener().