mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
audio: Bug fix: old API in JavaScript
This commit is contained in:
parent
65a8d4013a
commit
8d6ed85145
@ -17,6 +17,7 @@
|
|||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
@ -32,10 +33,10 @@ type player struct {
|
|||||||
bufferSource *js.Object
|
bufferSource *js.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
func startPlaying(src io.Reader, sampleRate int) error {
|
||||||
// Do nothing in node.js.
|
// Do nothing in node.js.
|
||||||
if js.Global.Get("require") != js.Undefined {
|
if js.Global.Get("require") != js.Undefined {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
class := js.Global.Get("AudioContext")
|
class := js.Global.Get("AudioContext")
|
||||||
@ -43,7 +44,7 @@ func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
|||||||
class = js.Global.Get("webkitAudioContext")
|
class = js.Global.Get("webkitAudioContext")
|
||||||
}
|
}
|
||||||
if class == js.Undefined {
|
if class == js.Undefined {
|
||||||
panic("audio: audio couldn't be initialized")
|
return errors.New("audio: audio couldn't be initialized")
|
||||||
}
|
}
|
||||||
p := &player{
|
p := &player{
|
||||||
src: src,
|
src: src,
|
||||||
@ -52,10 +53,7 @@ func startPlaying(src io.Reader, sampleRate int) (*player, error) {
|
|||||||
context: class.New(),
|
context: class.New(),
|
||||||
}
|
}
|
||||||
p.positionInSamples = int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
p.positionInSamples = int64(p.context.Get("currentTime").Float() * float64(p.sampleRate))
|
||||||
if err := p.start(); err != nil {
|
return p.start()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toLR(data []byte) ([]int16, []int16) {
|
func toLR(data []byte) ([]int16, []int16) {
|
||||||
|
Loading…
Reference in New Issue
Block a user