mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
audio: Refactoring: Remove initialize
This commit is contained in:
parent
76386213bd
commit
6f562f1b0a
@ -34,32 +34,23 @@ type player struct {
|
|||||||
|
|
||||||
var currentPlayer *player
|
var currentPlayer *player
|
||||||
|
|
||||||
func initialize() bool {
|
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 false
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if currentPlayer != nil || context != nil {
|
||||||
|
panic("audio: currentPlayer already exists")
|
||||||
|
}
|
||||||
class := js.Global.Get("AudioContext")
|
class := js.Global.Get("AudioContext")
|
||||||
if class == js.Undefined {
|
if class == js.Undefined {
|
||||||
class = js.Global.Get("webkitAudioContext")
|
class = js.Global.Get("webkitAudioContext")
|
||||||
}
|
}
|
||||||
if class == js.Undefined {
|
if class == js.Undefined {
|
||||||
return false
|
panic("audio: audio couldn't be initialized")
|
||||||
}
|
}
|
||||||
context = class.New()
|
context = class.New()
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func startPlaying(src io.Reader, sampleRate int) error {
|
|
||||||
if currentPlayer != nil {
|
|
||||||
panic("audio: currentPlayer already exists")
|
|
||||||
}
|
|
||||||
if context == nil {
|
|
||||||
if !initialize() {
|
|
||||||
panic("audio: audio couldn't be initialized")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPlayer = &player{
|
currentPlayer = &player{
|
||||||
src: src,
|
src: src,
|
||||||
|
Loading…
Reference in New Issue
Block a user