fheroes2 icon indicating copy to clipboard operation
fheroes2 copied to clipboard

Lagging or loss of audio when changing audio device at runtime

Open zenseii opened this issue 2 years ago • 6 comments

Preliminary checks

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.

zenseii avatar Nov 12 '22 01:11 zenseii

I believe this is a common problem for all devices, not Android only.

ihhub avatar Nov 12 '22 01:11 ihhub

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.

oleg-derevenetz avatar Nov 12 '22 10:11 oleg-derevenetz

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.

zenseii avatar Nov 12 '22 10:11 zenseii

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.

oleg-derevenetz avatar Nov 12 '22 11:11 oleg-derevenetz

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.

zenseii avatar Nov 22 '22 15:11 zenseii

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.

oleg-derevenetz avatar Nov 22 '22 15:11 oleg-derevenetz

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.

ihhub avatar Apr 01 '23 05:04 ihhub

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?

dood-apo avatar Jan 11 '24 13:01 dood-apo

Hi @dood-apo

  1. 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?
  2. Things that need to be restarted are somewhere inside SDL and may differ depending on SDL version.

oleg-derevenetz avatar Jan 11 '24 14:01 oleg-derevenetz

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.

oleg-derevenetz avatar Jan 28 '24 20:01 oleg-derevenetz

SDL 2.30 is out but we will update it after today's release.

ihhub avatar Feb 07 '24 02:02 ihhub

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.

oleg-derevenetz avatar Feb 07 '24 19:02 oleg-derevenetz

According to my tests on my Android 14 phone (Sony Xperia 1) this issue is gone with latest SDL (at least on Android).

oleg-derevenetz avatar Feb 08 '24 10:02 oleg-derevenetz

I can add that this works with no issues after this fix 👍

zenseii avatar Feb 19 '24 21:02 zenseii