mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 11:36:26 -05:00
Fix background music crash issue. (#880)
* Added useful config error panic. Added window title to panic window. * Fixed background music crash.
This commit is contained in:
parent
a9d832b539
commit
ce36dec7f8
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@
|
|||||||
tags
|
tags
|
||||||
heap.out
|
heap.out
|
||||||
heap.pdf
|
heap.pdf
|
||||||
|
.DS_Store
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
package ebiten
|
package ebiten
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
@ -31,6 +32,7 @@ type AudioProvider struct {
|
|||||||
asset *d2asset.AssetManager
|
asset *d2asset.AssetManager
|
||||||
audioContext *audio.Context // The Audio context
|
audioContext *audio.Context // The Audio context
|
||||||
bgmAudio *audio.Player // The audio player
|
bgmAudio *audio.Player // The audio player
|
||||||
|
bgmStream *wav.Stream
|
||||||
lastBgm string
|
lastBgm string
|
||||||
sfxVolume float64
|
sfxVolume float64
|
||||||
bgmVolume float64
|
bgmVolume float64
|
||||||
@ -46,7 +48,6 @@ func (eap *AudioProvider) PlayBGM(song string) {
|
|||||||
|
|
||||||
if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() {
|
if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() {
|
||||||
eap.bgmAudio.Pause()
|
eap.bgmAudio.Pause()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,13 +65,17 @@ func (eap *AudioProvider) PlayBGM(song string) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := wav.Decode(eap.audioContext, audioStream)
|
if _, err = audioStream.Seek(0, io.SeekStart); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
eap.bgmStream, err = wav.Decode(eap.audioContext, audioStream)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := audio.NewInfiniteLoop(d, d.Length())
|
s := audio.NewInfiniteLoop(eap.bgmStream, eap.bgmStream.Length())
|
||||||
eap.bgmAudio, err = audio.NewPlayer(eap.audioContext, s)
|
eap.bgmAudio, err = audio.NewPlayer(eap.audioContext, s)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user