barsoosayque / libgdx-oboe

🎶 libGDX audio replacement for Android (API 16+) built on top of Oboe.
MIT License
54 stars 10 forks source link

OboeAudio doesn't play music/sounds during entire first foreground session. #12

Closed codeniko closed 2 years ago

codeniko commented 2 years ago

I'm using libgdx's AndroidFragmentApplication and my game needs to play a looped background music piece as soon as the game loads. The issue is no music or sounds get played for the entire time the app is in foreground until you put app in background, and then back into foreground. Once it's in foreground for the second time, then music and sounds start playing without me having to invoke play() on any of them. I'm using the latest libgdxoboe 0.2.4.

Not sure if this is an issue related to using AndroidFragmentApplication instead of your README's AndroidApplication but the fix is to invoke resume() after creating the OboeAudio instance. I'm assuming the issue resolves itself when you bring app back into foreground a second time because resume gets invoked automatically. Just not that first time.

Note this wasn't something I had to do with Libgdx's default AndroidAudio.

  override fun createAudio(context: Context, config: AndroidApplicationConfiguration): AndroidAudio {
        return OboeAudio(context.assets).also {
            it.resume()
        }
    }
barsoosayque commented 2 years ago

Hmm. It's probably because of the new fragment class, yes. I need to look into that, I assume something in music lifetime changed in recent libGDX versions (and I didn't reflect those changes, as I haven't worked with libGDX in a while)

barsoosayque commented 2 years ago

Heh, totally forgot about that :sweat_smile:

Anyways, fixed in fc56d88e755c8c5cd823f5a1ff1c2badbc912446. There were some lifetime shenanigans in the earliest days of the lib, somehow I missed the basic step of resuming the default audio engine on start. Thanks for reporting :star:

If there are still problems, don't hesitate to reopen this issue. I've never worked with fragments, so I'm not sure if libgdx-oboe is 100% compatible with them as of now