allow no-sound mode in case of audio player creation error
This commit is contained in:
parent
0a88bd3727
commit
36f684133c
|
@ -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{
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue