I'm trying to play audio from this url: http://mtl2.liveatc.net/lbbg Here is my code:
public void setConnection(String url) {
String url = http://mtl2.liveatc.net/lbbg;
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
new Player().execute(url);
}
private class Player extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... strings) {
try {
mediaPlayer.setDataSource(strings[0]);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.stop();
mediaPlayer.reset();
}
});
mediaPlayer.prepareAsync();
} catch (Exception e) {
Log.e("MyAudioStreamingApp", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer mp) {
progressBar.setVisibility(View.INVISIBLE);
mp.start();
}
});
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressBar.setVisibility(View.VISIBLE);
}
}
And everything work, but with really huge delay. If I open this url in browser, it took near 20 seconds to start streaming, but when I run it in my app, it took up to 5-7 minutes.
UPD also add my log:
07-24 01:12:52.820 25918-25961/com.example I/OpenGLRenderer: Initialized EGL, version 1.4
07-24 01:12:52.843 25918-25961/com.example E/HAL: hw_get_module_by_class: module name gralloc
07-24 01:12:52.843 25918-25961/com.example E/HAL: hw_get_module_by_class: module name gralloc
07-24 01:12:59.171 25918-25918/com.example E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
07-24 01:12:59.171 25918-25918/com.example E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
07-24 01:12:59.171 25918-25918/com.example E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
07-24 01:12:59.171 25918-25918/com.example E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
07-24 01:12:59.188 25918-25931/com.example D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= stagefright/1.2 (Linux;Android 6.0.1)
07-24 01:12:59.191 25918-26002/com.example D/MediaHTTPConnection: proxy null port 0
07-24 01:12:59.192 25918-26002/com.example I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
07-24 01:15:42.557 25918-25925/com.example W/art: Suspending all threads took: 31.418ms
07-24 01:17:48.107 25918-25918/com.example D/MediaPlayer: setSubtitleAnchor in MediaPlayer
UPD2: My "solution": I couldn't find solution for this problem so I just decided to use next thing: I placed small WebView there I need play button, and received full audio player that load and play this stream in 10-15 seconds.