bgm.start(); VAR BGM = { typedefは:[ 'JI'、 'NIU'、 '陽'、 'NIAO' ]、 バッファ:{}、 コンテキスト:ヌル、 タイムアウト: 3000 、 開始:関数(){ この.cacheBuf()。 この.RUN(); }、 ラン:関数(){ VARの _this = この; setTimeout(関数(){ 場合(_this.context!= NULL ){ _this.context.close()。 _this.context = NULL ; } VAR _li = Math.floor((Math.random()* _this.typedef.length))。 _this.audioPlay(_this.typedef [_li])。 _this.run()。 }、_this.timeout)。 }、 audioplayが:機能(TP){ VARの _this = この; VAR _buff = _this.buffer [TP] .slice(0 、_this.buffer [TP] .byteLength)。 _this.context = 新しい(window.AudioContext || window.webkitAudioContext)(); _this.context.decodeAudioData(_buff、関数(バッファ){ VARのソース= _this.context.createBufferSource()。 source.buffer = バッファと source.connect(_this.context.destination)。 source.start( 0 )。 }); }、 cacheBuf:関数(){ VARの _this = この、_tp。 用(I における_this.typedef){ _tp = _this.typedef [I]。 _this.getbuf( '静的/オーディオ/' + _tp +」。mp3' 、_tp)。 } }、 getbuf:関数(URL、TP){ VARの _this = この; VAR XHR = 新しいですXMLHttpRequestを(); xhr.open( 'GET'、urlには、真の); xhr.responseType = 'arraybuffer' ; xhr.onreadystatechange = 関数(){ 場合(xhr.readyState === 4 && xhr.status === 200 ){ _this.buffer [TP] = xhr.response。 } }。 xhr.send(); } }。