mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Remove the error returning value from NewPlayerFromBytes
Updates #1380
This commit is contained in:
parent
83ead375a4
commit
29b4087ebf
@ -201,7 +201,7 @@ func (c *Context) IsReady() bool {
|
||||
// problematic when a user tries to play audio after the context is ready.
|
||||
// Play a dummy player to avoid the blocking (#969).
|
||||
// Use a long enough buffer so that writing doesn't finish immediately (#970).
|
||||
p, _ := NewPlayerFromBytes(c, make([]byte, bufferSize()*2))
|
||||
p := NewPlayerFromBytes(c, make([]byte, bufferSize()*2))
|
||||
p.Play()
|
||||
}()
|
||||
|
||||
@ -309,16 +309,14 @@ func NewPlayer(context *Context, src io.ReadCloser) (*Player, error) {
|
||||
// src can be shared by multiple players.
|
||||
//
|
||||
// The format of src should be same as noted at NewPlayer.
|
||||
//
|
||||
// NewPlayerFromBytes's error is always nil as of 1.5.0-alpha.
|
||||
func NewPlayerFromBytes(context *Context, src []byte) (*Player, error) {
|
||||
func NewPlayerFromBytes(context *Context, src []byte) *Player {
|
||||
b := BytesReadSeekCloser(src)
|
||||
p, err := NewPlayer(context, b)
|
||||
if err != nil {
|
||||
// Errors should never happen.
|
||||
panic(fmt.Sprintf("audio: %v at NewPlayerFromBytes", err))
|
||||
}
|
||||
return p, nil
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Player) finalize() {
|
||||
|
@ -179,7 +179,7 @@ func (p *Player) playSEIfNeeded() {
|
||||
if !inpututil.IsKeyJustPressed(ebiten.KeyP) {
|
||||
return
|
||||
}
|
||||
sePlayer, _ := audio.NewPlayerFromBytes(p.audioContext, p.seBytes)
|
||||
sePlayer := audio.NewPlayerFromBytes(p.audioContext, p.seBytes)
|
||||
sePlayer.Play()
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ func playNote(scoreIndex int) rune {
|
||||
square(l, vol, freq, 0.25)
|
||||
square(r, vol, freq, 0.25)
|
||||
|
||||
p, _ := audio.NewPlayerFromBytes(audioContext, toBytes(l, r))
|
||||
p := audio.NewPlayerFromBytes(audioContext, toBytes(l, r))
|
||||
p.Play()
|
||||
|
||||
return rune(note)
|
||||
|
@ -147,7 +147,7 @@ func init() {
|
||||
// playNote plays piano sound with the given frequency.
|
||||
func playNote(freq float64) {
|
||||
f := int(freq)
|
||||
p, _ := audio.NewPlayerFromBytes(audioContext, pianoNoteSamples[f])
|
||||
p := audio.NewPlayerFromBytes(audioContext, pianoNoteSamples[f])
|
||||
p.Play()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user