jarikomppa / soloud

Free, easy, portable audio engine for games
http://soloud-audio.com
Other
1.69k stars 270 forks source link

On some Android devices, when using OpenSL ES as a backend and connecting the phone via bluetooth to an audio device, there is no sound. + Solution. #285

Open VitorioK opened 3 years ago

VitorioK commented 3 years ago

Expected behavior: When connecting a mobile phone to an audio device via bluetooth, sound should play.

Actual behavior: When connecting the mobile phone to an audio device via bluetooth, there is no sound.

Steps to reproduce the problem:

  1. Build SoLoud-based Android application using OpenSL ES backend.
  2. Connect your mobile phone to an audio device via bluetooth.
  3. Play the sound. You won't hear anything.

SoLoud version 20200207

Operating system Android 8.0

Backend used: OpenSL ES

Mobile Phone Model: Samsung Galaxy A7 2017

Reason Early firing Callback "soloud_opensles_play_callback". This causes the variable "data->buffersQueued" to be -1. This will stop filling sound buffers in the worker thread.

How to Fix: In soloud\src\backend\opensles\soloud_opensles.cpp change the code in line 177. Was:

        if( event & SL_PLAYEVENT_HEADATEND )
        {
            data->buffersQueued--;
        }

New:

        if( event & SL_PLAYEVENT_HEADATEND )
        {
            if (data->buffersQueued > 0) data->buffersQueued--;
        }