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