I'm writing a small (personal use) app that plays an audio stream from the internet. The stream is an AAC audio stream. I can play that stream just fine on linux through mpv
and it plays immediately with no perceivable latency.
On Android, I'm first creating a MediaExtractor
to extract the data to decode, like this:
// tested URLs:
// https://r.dcs.redcdn.pl/sc/o2/Eurozet/live/audio.livx
// https://rs101-krk.rmfstream.pl/RMFFM48
String streamSource = ...;
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(streamSource);
extractor.selectTrack(0);
// it takes ~5 seconds to get there
this.format = extractor.getTrackFormat(0);
And for some reason there is a few seconds of delay from beginning downloading data to actually being able to get any information (like even track count, or select a track) from MediaExtractor
. This is both when I construct it with a URL and when I create my own StreamMediaSource
, and in this case it actually outputs any information after first reading about 130-150kiB of data, which at 64kbps is 16+ seconds of audio.
Is there any way to replicate the instant playback I can get on a PC? Why does it have to read that much data to proceed?