//!X_UA[ 'Blink' ] &&
// Firefox40.0.5 + Windows8 で音声が途中から鳴らなくなる
// Firefox41.0.1 + Windows8 で音声が途中から鳴らなくなる
- !( 40 <= X_UA[ 'Gecko' ] && X_UA[ 'Gecko' ] < 45 && X_UA[ 'Windows' ] ) &&
+ !( 40 <= X_UA[ 'Gecko' ] && X_UA[ 'Gecko' ] < 46 && X_UA[ 'Windows' ] ) &&
( window[ 'AudioContext' ] || window[ 'webkitAudioContext' ] ),
X_WebAudio_BUFFER_LIST = [],
X_WebAudio_need1stTouch = X_UA[ 'iOS' ],
audioBuffer : null,
bufferSource : null,
gainNode : null,
- _onended : null,
+ //_onended : null,
'Constructor' : function( disatcher, url, option ){
var i = 0,
this.playing && this.actualPause();
this.bufferSource && this._sourceDispose();
- this._onended && X_Closure_correct( this._onended );
+ //this._onended && X_Closure_correct( this._onended );
this.gainNode && this.gainNode.disconnect();
},
end = X_Audio_getEndTime( this );
begin = X_Audio_getStartTime( this, end, true );
- console.log( '[WebAudio] play ' + begin + ' -> ' + end );
+ console.log( '[WebAudio] play ' + begin + ' -> ' + end + ' loop: ' + this.autoLoop + ' :' + this.loopStartTime + ' -> ' + this.loopEndTime );
if( this.bufferSource ) this._sourceDispose();
if( !this.gainNode ){
this.gainNode = X_WebAudio_context[ 'createGain' ] ? X_WebAudio_context[ 'createGain' ]() : X_WebAudio_context[ 'createGainNode' ]();
- this.gainNode[ 'connect' ]( X_WebAudio_context[ 'destination' ] );
+ this.gainNode[ 'connect' ]( X_WebAudio_context[ 'destination' ] );
};
+
this.bufferSource = X_WebAudio_context[ 'createBufferSource' ]();
this.bufferSource.buffer = this.audioBuffer;
- this.bufferSource[ 'connect' ]( this.gainNode );
+ /* win8.1 Firefox45, win8.1 Chrome48 で動かなくなる...
+ if( this.bufferSource[ 'loop' ] = this.autoLoop ){
+ this.bufferSource[ 'loopStart' ] = 0 <= this.loopStartTime ? this.loopStartTime / 1000 : begin / 1000;
+ this.bufferSource[ 'loopEnd' ] = 0 <= this.loopEndTime ? this.loopEndTime / 1000 : end / 1000;
+ }; */
+
+ this.bufferSource[ 'connect' ]( this.gainNode );
this.gainNode[ 'gain' ].value = this.gain;
// おかしい、stop 前に外していても呼ばれる、、、@Firefox33.1
//};
if( this.bufferSource.start ){
- this.bufferSource.start( 0, begin / 1000, end / 1000 );
+ this.bufferSource.start( 0, begin / 1000, ( end - begin ) / 1000 );
+ } else
+ if( this.bufferSource[ 'noteOn' ] ){
+ this.bufferSource[ 'noteOn' ]( 0, begin / 1000, ( end - begin ) / 1000 );
} else {
- this.bufferSource[ 'noteGrainOn' ]( 0, begin / 1000, end / 1000 );
+ this.bufferSource[ 'noteGrainOn' ]( 0, begin / 1000, ( end - begin ) / 1000 );
};
this.playing = true;
this._startPos = begin;
this._endPosition = end;
this._startTime = X_WebAudio_context.currentTime * 1000;
- // this._interval = this._interval || X_Timer_add( 1000, 0, this, this._onInterval );
- this._interval = this._interval || X_Timer_add( 100, 0, this, this._onEnded );
+ this._interval = this._interval || X_Timer_add( 100, 0, this, this._onInterval );
},
_sourceDispose : function(){
this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );
}, */
- _onEnded : function(){
+ _onInterval : function(){
var time;
- //delete this._timerID;
if( this.playing ){
+ // TODO 再生中に終了時間だけ変えた場合!
time = X_WebAudio_context.currentTime * 1000 - this._startTime - this._endPosition + this._startPos | 0;
//console.log( '> onEnd ' + ( this.playing && ( X_WebAudio_context.currentTime * 1000 - this._startTime ) ) + ' < ' + ( this._endPosition - this._startPos ) );
- if( this._onended ){
- // Firefox 用の対策,,,
- if( time < 0 ) return;
- } else {
- if( time < 0 ){
- this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );
- //console.log( '> onEnd crt:' + ( X_WebAudio_context.currentTime * 1000 ) + ' startTime:' + this._startTime +
- // ' from:' + this._startPos + ' to:' + this._endPosition );
- // this._timerID = X_Timer_once( -time, this, this._onEnded );
- return;
- };
- };
+
+ if( time < 0 ){
+ this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );
+ return;
+ };
if( this.autoLoop ){
if( !( this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){
actualPause : function(){
console.log( '[WebAudio] pause' );
- //this._timerID && X_Timer_remove( this._timerID );
- //delete this._timerID;
this._interval && X_Timer_remove( this._interval );
delete this._interval;
delete this.playing;
if( this.bufferSource ){
- //if( this.bufferSource.onended ) delete this.bufferSource.onended;
-
this.bufferSource.stop ?
this.bufferSource.stop( 0 ) : this.bufferSource[ 'noteOff' ]( 0 );
};