From 36f684133c154c8c464ae6c3bc3e2adc86588ee9 Mon Sep 17 00:00:00 2001 From: sqshq Date: Sat, 3 Aug 2019 17:54:41 -0400 Subject: [PATCH] allow no-sound mode in case of audio player creation error --- asset/player.go | 6 +++++- data/trigger.go | 2 +- main.go | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/asset/player.go b/asset/player.go index 92d8955..3814e40 100644 --- a/asset/player.go +++ b/asset/player.go @@ -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{ diff --git a/data/trigger.go b/data/trigger.go index 16c7480..d331f87 100644 --- a/data/trigger.go +++ b/data/trigger.go @@ -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() } diff --git a/main.go b/main.go index cb22444..47ebccf 100644 --- a/main.go +++ b/main.go @@ -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())