Music controller - Fix pause (#5307)

This commit is contained in:
SomeTroglodyte
2021-09-24 09:00:46 +02:00
committed by GitHub
parent bae8bd2468
commit 8ef84d785e
4 changed files with 11 additions and 2 deletions

View File

@ -167,7 +167,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
override fun dispose() {
cancelDiscordEvent?.invoke()
Sounds.clearCache()
if (::musicController.isInitialized) musicController.shutdown()
if (::musicController.isInitialized) musicController.gracefulShutdown() // Do allow fade-out
// Log still running threads (on desktop that should be only this one and "DestroyJavaVM")
val numThreads = Thread.activeCount()

View File

@ -193,7 +193,7 @@ class MusicController {
/**
* Chooses and plays a music track using an adaptable approach - for details see the wiki.
* Called without parameters it will choose a new ambient music track and start playing it with fade-in/out.
* Will do nothing when no music files exist.
* Will do nothing when no music files exist or the master volume is zero.
*
* @param prefix file name prefix, meant to represent **Context** - in most cases a Civ name or default "Ambient"
* @param suffix file name suffix, meant to represent **Mood** - e.g. Peace, War, Theme...
@ -205,6 +205,8 @@ class MusicController {
suffix: String = "",
flags: EnumSet<MusicTrackChooserFlags> = EnumSet.noneOf(MusicTrackChooserFlags::class.java)
): Boolean {
if (baseVolume == 0f) return false
val musicFile = chooseFile(prefix, suffix, flags)
if (musicFile == null) {
@ -265,6 +267,8 @@ class MusicController {
if ((state != ControllerState.Playing && state != ControllerState.PlaySingle) || current == null) return
val fadingStep = defaultFadingStep * speedFactor.coerceIn(0.001f..1000f)
current!!.startFade(MusicTrackController.State.FadeOut, fadingStep)
if (next?.state == MusicTrackController.State.FadeIn)
next!!.startFade(MusicTrackController.State.FadeOut)
state = ControllerState.Pause
}

View File

@ -105,6 +105,8 @@ class MusicTrackController(private var volume: Float) {
return
}
fadeVolume = 0f
music!!.volume = 0f
music!!.pause()
state = State.Idle
}

View File

@ -108,6 +108,9 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam
ToastPopup("Not enough memory on phone to load game!", this)
}
// resume music (in case choices from the menu lead to instantiation of a new WorldScreen)
UncivGame.Current.musicController.resume()
techButtonHolder.touchable = Touchable.enabled
techButtonHolder.onClick(UncivSound.Paper) {
game.setScreen(TechPickerScreen(viewingCiv))