Merge pull request #12 from sqshq/allow-no-sound-mode

Allow no-sound mode in case of audio player creation error
This commit is contained in:
Alexander Lukyanchikov 2019-08-03 18:11:27 -04:00 committed by GitHub
commit 5c5281683f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()
if player != nil {
defer player.Close()
}
defer handleCrash(statistics, opt, bc)
defer updateStatistics(cfg, time.Now())