fheroes2
fheroes2 copied to clipboard
Lagging or loss of audio when changing audio device at runtime
Preliminary checks
- [X] I've checked that there aren't other open issues on the same topic.
- [X] I've checked that this issue is reproducible on the latest snapshot build.
Platform
Other
Describe the bug
When running the game and plugging in a wired headset or connecting a Bluetooth one, the app will freeze. On Android it is intermittent and you can interrupt it briefly by tapping the screen.
On Windows 8 I do not observe any problem.
The only way to fix it is by closing the app entirely and then restart it with the audio device of choice already connected.
Changing sound source (midi/external) or volumes changes nothing.
I believe it has always been like this so it's not a regression.
Save file
No need. Audio issues from the beginning.
Additional info
The device is a Samsung smartphone.
I believe this is a common problem for all devices, not Android only.
On my Android phone the behavior is different - there are no lags after connecting the headset, but there is no sound either. Sound appears only after game restart.
Yes, I did observe a similar issue on my Windows 10 PC, but there I can only get audio through headsets and never through speakers, no matter what I try, I thought it could be due to issues with that laptop's setup because it has other issues regarding audio output.
I'll adjust this issue accordingly. Would be interesting to hear about other systems like Mac and Linux.
but there I can only get audio through headsets and never through speakers, no matter what I try
I still can get audio through the headset, just not on-the-fly - game restart is needed.
In the latest snapshot build the audio just disappears and the intermittent hitches and return of audio are gone. The only way to correct the audio is to restart the app.
I also found that on Win 8 none of these issues are observed.
I suppose that this depends on audio driver. If audio driver supports seamless switching of an already opened audio device to the headset, then it works. If not, then app restart is needed.
SDL has events related to audio device appearance and status change. I did an initial investigation in the past and couldn't find any easy solution. We might need to restart at least audio manager in order to fix the problem. However, the bottleneck in this solution is that we have no idea whether the current audio device being changed or something else.
How about listening for MediaRouter callbacks with MediaControlIntent.CATEGORY_LIVE_AUDIO selector? This should ping us whenever there is some change in the audio routing, so we could restart what needs to be restarted. Does it make sense?
Hi @dood-apo
- What you are talking about is Android-only thing, and it would be better to avoid any platform-specific crutches in our code as much as possible, because then why do we need a platform-independent framework like SDL? And what about other platforms like Windows?
- Things that need to be restarted are somewhere inside SDL and may differ depending on SDL version.
This should be fixed in SDL recently:
https://github.com/libsdl-org/SDL/pull/8937
This should be verified when the next SDL release is out.
SDL 2.30 is out but we will update it after today's release.
Hi @zenseii if you have the opportunity to build fheroes2 for Android using Android Studio, you can download the android.zip
artifact from here, extract its contents to the android
directory of the fheroes2 project and then build & run fheroes2 on your devices to test the behavior when changing the audio output device.
According to my tests on my Android 14 phone (Sony Xperia 1) this issue is gone with latest SDL (at least on Android).
I can add that this works with no issues after this fix 👍