audio: Refactoring: Remove initialize

This commit is contained in:
Hajime Hoshi 2016-03-05 02:02:19 +09:00
parent 76386213bd
commit 6f562f1b0a

View File

@ -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
panic("audio: audio couldn't be initialized")
}
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{
src: src,