Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with MediaPlayer buffering time when streaming audio

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.

like image 989
StackOverflower Avatar asked Apr 03 '15 13:04

StackOverflower


People also ask

Why does my music keep buffering?

If you're accessing the internet via Wi-Fi, constant buffering may mean that you don't have a strong connection to the network. Moving closer to the signal source or removing barriers between you and the signal can improve signal strength. Try loading other media to test your connection.

Why does my radio station keep buffering?

You may experience frequent buffering if your network connection doesn't have enough bandwidth for your station's stream. One useful tool for reducing buffering pauses when the network connection is unreliable is the "Buffer Before Play" option in the TuneIn Settings menu.

What is the default buffering time for Windows Media Player?

Windows Media Redirection buffer size By default, the buffer size is 5 seconds.


1 Answers

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

like image 103
Kai Avatar answered Nov 16 '22 03:11

Kai