mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +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
|
||||
|
||||
func initialize() bool {
|
||||
func startPlaying(src io.Reader, sampleRate int) error {
|
||||
// Do nothing in node.js.
|
||||
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")
|
||||
if class == js.Undefined {
|
||||
class = js.Global.Get("webkitAudioContext")
|
||||
}
|
||||
if class == js.Undefined {
|
||||
return false
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
context = class.New()
|
||||
|
||||
currentPlayer = &player{
|
||||
src: src,
|
||||
|
Loading…
Reference in New Issue
Block a user