I'm using MediaPlayer
to stream a radio over HTTP. On Lollipop my stream takes about a minute to start which is unacceptable. It takes about 20 seconds on Kitkat, which is already a pain but now became unusable.
There is a well known problem with this component related to buffering: the amount of bytes to buffer is harcoded and can't be changed.
My code is really standard
player.reset();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(streamUrl);
player.prepareAsync();
And on prepared I do
player.start();
I've heard about alternatives as GStreamer
but I couldn't make it work on Windows.
I wonder if anyone has a working solution to stream radio over HTTP with a decent start delay.
EDIT
I tested ExoPlayer but the lower start time I get is 15 seconds. The player is stuck on "preparing" state (not buffering, that's later so far I see).
EDIT
The format of the stream is AAC
EDIT
I tested https://code.google.com/p/aacdecoder-android/ but the only problem this library has is the lack of support to stream pause. It's a requirement of my application to support pause on online stream.
If your use case is compatible with GPL/LGPL licenses, then VLC should be exactly what you need. VLC is able to stream from your URL on a 3G network with only ~1 sec delay.
Step 1: Download VLC source code and compile per the instruction
Step 2:
The most important class is org.videolan.vlc.audio.AudioServiceController
, which was called from org.videolan.vlc.gui.MRLPanelFragement.processUri() --> org.videolan.vlc.util.Util.openStream(Context, String) --> AudioServiceController.load(String, boolean)
. You can remove all the unnecessary code other than AudioServiceController
and its support classes to slim down the size