1

I'm developing an application with playing audio. In several cases I change the AudioStreamType to AudioManager.STREAM_RING(is mode when music is playing both: speakers and headset). When I use Bluetooth headset, I have a small annoying delay.

So i was reading that Bluetooth has a buffer and and this is logical , but how I can solve this? Also i tried to change buffer size or delay for mediaPlayer.

So, i create a mediaPlayer like as:

@Override
public void onInit() {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setLooping(true);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); 
    songManager = new SongsManager(context);
}

@Override
public void onPrepare() {
    // prepare media player
    if (mediaPlayer != null) {
        mediaPlayer.reset();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
        absolutePathToPlayingSong = /*some place*/;
        mediaPlayer.setDataSource(/*some place*/);
        mediaPlayer.prepare();
        mediaPlayer.setVolume(volumeLvl, volumeLvl);
    }

    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
}

then i just start player:

mediaPlayer.start();

So, i already tried:

  1. to change a prepare() to prepareAsync() - probably it was tiny help, to may be i had a sound hallucinations. Unfortunately it broke a seekTo() in one place
  2. added onPrepared() and start playing from listener - I not sure that it help

Give me please any advance^ how to fix delay for Bluetooth headset? I checked this device in YouTube application and it work great. So problem in my application. sorry my bad English!)

I have 2 target devices android 7.0(SDK 24) and android 4.2 (SDK 16)

Georgiy Chebotarev
  • 1,676
  • 3
  • 14
  • 18
  • See also [this question](https://stackoverflow.com/questions/15034198/streaming-to-built-in-speakers-and-bluetooth-speakers-simultaneously). – greeble31 Nov 09 '18 at 13:24
  • Probably somebody it helps: https://stackoverflow.com/a/42582893/7449805 I can't used it, because my API < 24 – Georgiy Chebotarev Nov 12 '18 at 12:58

0 Answers0