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