allow no-sound mode in case of audio player creation error

This commit is contained in:
sqshq 2019-08-03 17:54:41 -04:00
parent 0a88bd3727
commit 36f684133c
3 changed files with 9 additions and 3 deletions

View File

@ -21,7 +21,11 @@ func NewAudioPlayer() *AudioPlayer {
player, err := oto.NewPlayer(44100, 2, 2, 8192) player, err := oto.NewPlayer(44100, 2, 2, 8192)
if err != nil { if err != nil {
panic(err) // it is expected to fail when some of the system
// libraries are not available (e.g. libasound2)
// it is not the main functionality of the application,
// so we allow startup in no-sound mode
return nil
} }
return &AudioPlayer{ return &AudioPlayer{

View File

@ -74,7 +74,7 @@ func (t *Trigger) Execute(sample *Sample) {
fmt.Print(console.BellCharacter) fmt.Print(console.BellCharacter)
} }
if t.actions.sound { if t.actions.sound && t.player != nil {
t.player.Beep() t.player.Beep()
} }

View File

@ -84,7 +84,9 @@ func main() {
defer console.Close() defer console.Close()
player := asset.NewAudioPlayer() player := asset.NewAudioPlayer()
if player != nil {
defer player.Close() defer player.Close()
}
defer handleCrash(statistics, opt, bc) defer handleCrash(statistics, opt, bc)
defer updateStatistics(cfg, time.Now()) defer updateStatistics(cfg, time.Now())