From 6f562f1b0a48c3bfae1599415221ed3d57e53d9d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 5 Mar 2016 02:02:19 +0900 Subject: [PATCH] audio: Refactoring: Remove initialize --- exp/audio/audio_js.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/exp/audio/audio_js.go b/exp/audio/audio_js.go index af94e38d1..7b083d8ee 100644 --- a/exp/audio/audio_js.go +++ b/exp/audio/audio_js.go @@ -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,