-var X_Audio_WebAudio_context = !X_UA.iPhone_4s && !X_UA.iPad_2Mini1 && !X_UA.iPod_4 &&
- !( X_UA.Gecko && X_UA.Android ) &&
+var X_Audio_WebAudio_context = !X_UA[ 'iPhone_4s' ] && !X_UA[ 'iPad_2Mini1' ] && !X_UA[ 'iPod_4' ] &&
+ !( X_UA[ 'Gecko' ] && X_UA[ 'Android' ] ) &&
( window.AudioContext || window.webkitAudioContext ),
X_Audio_WebAudioWrapper;
autoplay : false,
volume : 0.5,
+ _startPos : 0,
+ _endPosition : 0,
_startTime : 0,
- _endTime : 0,
- _playTime : 0,
_timerID : 0,
_interval : 0,
buffer : null,
audio.proxy.listenOnce( 'canplaythrough', this, this._onBufferReady );
} else {
this.xhr = X.Net.xhrGet( url, 'arraybuffer' )
- .listen( X.Event.PROGRESS, this )
- .listenOnce( [ X.Event.SUCCESS, X.Event.COMPLETE, X.Event.CANCELED ], this );
+ .listen( X_Event.PROGRESS, this )
+ .listenOnce( [ X_Event.SUCCESS, X_Event.COMPLETE, X_Event.CANCELED ], this );
};
},
handleEvent : function( e ){
switch( e.type ){
- case X.Event.PROGRESS :
+ case X_Event.PROGRESS :
e.percent ?
this.proxy.dispatch( { type : 'progress', percent : e.percent } ) :
this.proxy.dispatch( 'loadstart' );
return;
- case X.Event.SUCCESS :
+ case X_Event.SUCCESS :
console.log( 'WebAudio xhr success! ' + !!X_Audio_WebAudio_context.decodeAudioData + ' t:' + typeof e.data );
// TODO 旧api
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Porting_webkitAudioContext_code_to_standards_based_AudioContext
// iOS 7.1 で decodeAudioData に処理が入った瞬間にスクリーンを長押しする(スクロールを繰り返す)と
// decoeAudioData の処理がキャンセルされることがある(エラーやコールバックの発火もなく、ただ処理が消滅する)。
// ただし iOS 8.1.2 では エラーになる
- if( X_Audio_WebAudio_context.createBuffer && X_UA.iOS < 8 ){
+ if( X_Audio_WebAudio_context.createBuffer && X_UA[ 'iOS' ] < 8 ){
this._onDecodeSuccess( X_Audio_WebAudio_context.createBuffer( e.data, false ) );
} else
if( X_Audio_WebAudio_context.decodeAudioData ){
};
break;
- case X.Event.CANCELED :
+ case X_Event.CANCELED :
this.error = 1;
this.proxy.dispatch( 'aborted' );
break;
- case X.Event.COMPLETE :
+ case X_Event.COMPLETE :
this.error = 2;
- this.proxy.asyncDispatch( { type : X.Event.ERROR, message : 'xhr error' } );
+ this.proxy.asyncDispatch( { type : X_Event.ERROR, message : 'xhr error' } );
break;
};
- this.xhr.unlisten( [ X.Event.PROGRESS, X.Event.SUCCESS, X.Event.COMPLETE, X.Event.CANCELED ], this );
+ this.xhr.unlisten( [ X_Event.PROGRESS, X_Event.SUCCESS, X_Event.COMPLETE, X_Event.CANCELED ], this );
delete this.xhr;
},
this.onDecodeSuccess && this._onDecodeComplete();
if ( !buffer ) {
- this.proxy.asyncDispatch( { type : X.Event.ERROR, message : 'buffer is ' + buffer } );
+ this.proxy.asyncDispatch( { type : X_Event.ERROR, message : 'buffer is ' + buffer } );
return;
};
this.proxy.asyncDispatch( 'canplay' );
this.proxy.asyncDispatch( 'canplaythrough' );
*/
- this.proxy.asyncDispatch( X.Event.READY );
+ this.proxy.asyncDispatch( X_Event.READY );
this.autoplay && X.Timer.once( 16, this, this.play );
console.log( 'WebAudio decode error!' );
this._onDecodeComplete();
this.error = 3;
- this.proxy.asyncDispatch( { type : X.Event.ERROR, message : 'decode error' } );
+ this.proxy.asyncDispatch( { type : X_Event.ERROR, message : 'decode error' } );
},
_onDecodeComplete : function(){
this.source.noteGrainOn( 0, begin / 1000, end / 1000 );
};
- this.playing = true;
- this._startTime = begin;
- this._endTime = end;
- this._playTime = X_Audio_WebAudio_context.currentTime * 1000;
- this._interval = this._interval || X.Timer.add( 1000, 0, this, this._onInterval );
+ this.playing = true;
+ this._startPos = begin;
+ this._endPosition = end;
+ this._startTime = X_Audio_WebAudio_context.currentTime * 1000;
+ this._interval = this._interval || X.Timer.add( 1000, 0, this, this._onInterval );
},
_onInterval : function(){
delete this._interval;
return X_Callback_UN_LISTEN;
};
- this.proxy.dispatch( X.Event.MEDIA_PLAYING );
+ this.proxy.dispatch( X_Event.MEDIA_PLAYING );
},
_onEnded : function(){
delete this._timerID;
if( this.playing ){
- time = X_Audio_WebAudio_context.currentTime * 1000 - this._playTime - this._endTime + this._startTime | 0;
- //console.log( '> onEnd ' + ( this.playing && ( X_Audio_WebAudio_context.currentTime * 1000 - this._playTime ) ) + ' < ' + ( this._endTime - this._startTime ) );
+ time = X_Audio_WebAudio_context.currentTime * 1000 - this._startTime - this._endPosition + this._startPos | 0;
+ //console.log( '> onEnd ' + ( this.playing && ( X_Audio_WebAudio_context.currentTime * 1000 - this._startTime ) ) + ' < ' + ( this._endPosition - this._startPos ) );
if( this._onended ){
// Firefox 用の対策,,,
if( time < 0 ) return;
} else {
if( time < 0 ){
- console.log( '> onEnd ' + ( -time ) + ' start:' + this._startTime + '-' + this._endTime );
+ console.log( '> onEnd crt:' + ( X_Audio_WebAudio_context.currentTime * 1000 ) + ' startTime:' + this._startTime +
+ ' from:' + this._startPos + ' to:' + this._endPosition );
this._timerID = X.Timer.once( -time, this, this._onEnded );
return;
};
};
if( this.loop ){
- if( !( this.proxy.dispatch( X.Event.MEDIA_BEFORE_LOOP ) & X.Callback.PREVENT_DEFAULT ) ){
+ if( !( this.proxy.dispatch( X_Event.MEDIA_BEFORE_LOOP ) & X.Callback.PREVENT_DEFAULT ) ){
this.looped = true;
- this.proxy.dispatch( X.Event.MEDIA_LOOPED );
+ this.proxy.dispatch( X_Event.MEDIA_LOOPED );
this.play();
};
} else {
this.pause();
- this.proxy.dispatch( X.Event.MEDIA_ENDED );
+ this.proxy.dispatch( X_Event.MEDIA_ENDED );
};
};
},
playing : this.playing,
duration : this.duration,
- currentTime : this.playing ? ( X_Audio_WebAudio_context.currentTime * 1000 - this._playTime + this._startTime | 0 ) : this.seekTime,
+ currentTime : this.playing ? ( X_Audio_WebAudio_context.currentTime * 1000 - this._startTime + this._startPos | 0 ) : this.seekTime,
error : this.error
};
};
//
detect : function( proxy, source, ext ){
- proxy.asyncDispatch( X_Audio_codecs[ ext ] ? X_Audio_CAN_PLAY : X_Audio_NOT_PLAY );
+ proxy.asyncDispatch( { type : X_Event.COMPLETE, canPlay : X_Audio_codecs[ ext ] } );
},
klass : X_Audio_WebAudioWrapper