Live streaming audio delays while playing android-16?

I am developing a small Android application in which I play the rtsp link using an Android media player. It works correctly on less android 16 api. but the problem is that when I run on android 16, it takes a lot of time to play, and for a while it doesn't even play. Next up is the code I'm using

sdrPlayer = new MediaPlayer();
sdrPlayer.setDataSource(url);
sdrPlayer.prepare();
sdrPlayer.setOnCompletionListener(video.this);
sdrPlayer.setOnPreparedListener(video.this);
sdrPlayer.setOnBufferingUpdateListener(video.this);
sdrPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

Below is some test case

  • ZTE N860 - It takes about 4 - 5 minutes to start playing the radio.
  • Samsung Galaxy S4 - Audio doesn't work at all. It calls the start method in onprepare, but there is no sound.
  • Samsung SCH1415 - It takes about 8 minutes to start playing the radio.
  • HTC V5 - Audio does not work all the time. He starts to play, but there is no sound. The behavior is inconsistent and causes more frustration.
+5
source share
1 answer

to play the rtsp link you should use sdrPlayer.prepareAsync();instead

sdrPlayer.prepare();

as the documentation states

It prepares the player for playback asynchronously. After installing the data source and display surface, you need to either call prepare()or prepareAsync(). For threads, you must callprepareAsync() that immediately returns, and does not block until enough data has been buffered.

+3
source

All Articles