Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

live Streaming audio delays while playing in android-16?

I am developing a small android application in which i am playing the rtsp link using android media player .It is working properly on less then android 16 api. but the problem is that when i run on android 16 it take lots of time to play and some time it even does not play.following is the code which I am 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);

Following are some test case

  1. ZTE N860 – Takes about 4 to 5 mins to start playing the Radio.
  2. Samsung Galaxy S4 – Audio doesn’t work at all. It call start method in onprepare method but there is no audio.
  3. Samsung SCH1415 - Takes about 8 mins to start playing the Radio
  4. HTC V5 – Audio doesn’t work all the time. It starts playing but there is no audio. The behavior is inconsistent and that’s causing more frustration.
like image 253
Nitin Avatar asked Oct 22 '22 11:10

Nitin


1 Answers

for playing rtsp link you should use sdrPlayer.prepareAsync(); instead of

sdrPlayer.prepare();

because the documentation says

It prepares the player for playback, asynchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.

like image 75
user163942 Avatar answered Nov 02 '22 09:11

user163942