examples/audio: Remove unneeded error handlings

This commit is contained in:
Hajime Hoshi 2017-06-03 01:40:22 +09:00
parent fb85bcf104
commit 7bb917d4f6

View File

@ -72,21 +72,20 @@ func playerBarRect() (x, y, w, h int) {
return return
} }
func (p *Player) updateSE() error { func (p *Player) updateSE() {
if seBytes == nil { if seBytes == nil {
return nil return
} }
if !ebiten.IsKeyPressed(ebiten.KeyP) { if !ebiten.IsKeyPressed(ebiten.KeyP) {
keyState[ebiten.KeyP] = 0 keyState[ebiten.KeyP] = 0
return nil return
} }
keyState[ebiten.KeyP]++ keyState[ebiten.KeyP]++
if keyState[ebiten.KeyP] != 1 { if keyState[ebiten.KeyP] != 1 {
return nil return
} }
sePlayer, _ := audio.NewPlayerFromBytes(audioContext, seBytes) sePlayer, _ := audio.NewPlayerFromBytes(audioContext, seBytes)
sePlayer.Play() sePlayer.Play()
return nil
} }
func (p *Player) updateVolume() { func (p *Player) updateVolume() {
@ -108,23 +107,24 @@ func (p *Player) updateVolume() {
p.audioPlayer.SetVolume(float64(volume128) / 128) p.audioPlayer.SetVolume(float64(volume128) / 128)
} }
func (p *Player) updatePlayPause() error { func (p *Player) updatePlayPause() {
if p.audioPlayer == nil { if p.audioPlayer == nil {
return nil return
} }
if !ebiten.IsKeyPressed(ebiten.KeyS) { if !ebiten.IsKeyPressed(ebiten.KeyS) {
keyState[ebiten.KeyS] = 0 keyState[ebiten.KeyS] = 0
return nil return
} }
keyState[ebiten.KeyS]++ keyState[ebiten.KeyS]++
if keyState[ebiten.KeyS] != 1 { if keyState[ebiten.KeyS] != 1 {
return nil return
} }
if p.audioPlayer.IsPlaying() { if p.audioPlayer.IsPlaying() {
return p.audioPlayer.Pause() p.audioPlayer.Pause()
return
} }
p.audioPlayer.Play() p.audioPlayer.Play()
return nil return
} }
func (p *Player) updateBar() { func (p *Player) updateBar() {
@ -178,12 +178,8 @@ func update(screen *ebiten.Image) error {
} }
if musicPlayer != nil { if musicPlayer != nil {
musicPlayer.updateBar() musicPlayer.updateBar()
if err := musicPlayer.updatePlayPause(); err != nil { musicPlayer.updatePlayPause()
return err musicPlayer.updateSE()
}
if err := musicPlayer.updateSE(); err != nil {
return err
}
musicPlayer.updateVolume() musicPlayer.updateVolume()
} }
if ebiten.IsRunningSlowly() { if ebiten.IsRunningSlowly() {