mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Use io.ReadSeeker instead of ReadSeekCloser
This commit is contained in:
parent
bca9b0d3f1
commit
8e43d1047b
@ -20,13 +20,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/audio"
|
||||
)
|
||||
|
||||
type ReadSeekCloser interface {
|
||||
io.ReadSeeker
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
src ReadSeekCloser
|
||||
src io.ReadSeeker
|
||||
sampleRate int
|
||||
}
|
||||
|
||||
@ -38,7 +33,7 @@ type Player struct {
|
||||
// without a header (e.g. RIFF header).
|
||||
//
|
||||
// TODO: Pass sample rate and num of channels.
|
||||
func NewPlayer(src ReadSeekCloser, sampleRate int) *Player {
|
||||
func NewPlayer(src io.ReadSeeker, sampleRate int) *Player {
|
||||
return &Player{
|
||||
src: src,
|
||||
sampleRate: sampleRate,
|
||||
|
@ -18,15 +18,10 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
type ReadSeekCloser interface {
|
||||
io.ReadSeeker
|
||||
io.Closer
|
||||
}
|
||||
|
||||
func Init() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
func Play(src ReadSeekCloser, sampleRate int) error {
|
||||
func Play(src io.ReadSeeker, sampleRate int) error {
|
||||
return play(src, sampleRate)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
@ -25,7 +26,7 @@ import (
|
||||
var context *js.Object
|
||||
|
||||
type audioProcessor struct {
|
||||
src ReadSeekCloser
|
||||
src io.ReadSeeker
|
||||
sampleRate int
|
||||
position float64
|
||||
}
|
||||
@ -68,7 +69,7 @@ func (a *audioProcessor) play() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func play(src ReadSeekCloser, sampleRate int) error {
|
||||
func play(src io.ReadSeeker, sampleRate int) error {
|
||||
a := &audioProcessor{
|
||||
src: src,
|
||||
sampleRate: sampleRate,
|
||||
|
@ -17,6 +17,7 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mobile/exp/audio"
|
||||
@ -24,10 +25,18 @@ import (
|
||||
|
||||
var players = map[*audio.Player]struct{}{}
|
||||
|
||||
func play(src ReadSeekCloser, sampleRate int) error {
|
||||
type readSeekCloser struct {
|
||||
io.ReadSeeker
|
||||
}
|
||||
|
||||
func (r *readSeekCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func play(src io.ReadSeeker, sampleRate int) error {
|
||||
// TODO: audio.NewPlayer interprets WAV header, which we don't want.
|
||||
// Use OpenAL or native API instead.
|
||||
p, err := audio.NewPlayer(src, audio.Stereo16, int64(sampleRate))
|
||||
p, err := audio.NewPlayer(&readSeekCloser{src}, audio.Stereo16, int64(sampleRate))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user