diff --git a/exp/audio/audio.go b/exp/audio/audio.go index 3b50564cb..9becf0bfa 100644 --- a/exp/audio/audio.go +++ b/exp/audio/audio.go @@ -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, diff --git a/internal/audio/audio.go b/internal/audio/audio.go index 76b2fcf7c..035088ce6 100644 --- a/internal/audio/audio.go +++ b/internal/audio/audio.go @@ -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) } diff --git a/internal/audio/audio_js.go b/internal/audio/audio_js.go index e6b62349a..ecc2a6a5e 100644 --- a/internal/audio/audio_js.go +++ b/internal/audio/audio_js.go @@ -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, diff --git a/internal/audio/audio_openal.go b/internal/audio/audio_openal.go index 07102aaab..c111a8271 100644 --- a/internal/audio/audio_openal.go +++ b/internal/audio/audio_openal.go @@ -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 }