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)
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{

View File

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

View File

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