X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F07_audio%2F01_XWebAudio.js;h=fb4a95f1c6f2cf4e587e4be917bf86565757cfd1;hb=42e0982b02a99c71702ce8cd8740645aefdc8097;hp=38a9e8c07c04bc5f8c4d1088b70ba6e8e0d7168a;hpb=a130cabd01fde8865990a59d849f5d5d08ed2119;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/07_audio/01_XWebAudio.js b/0.6.x/js/07_audio/01_XWebAudio.js index 38a9e8c..fb4a95f 100644 --- a/0.6.x/js/07_audio/01_XWebAudio.js +++ b/0.6.x/js/07_audio/01_XWebAudio.js @@ -18,7 +18,7 @@ if( X_Audio_WebAudio_context ){ }; }; - X_Audio_WebAudioWrapper = X.EventDispatcher.inherits( + X_Audio_WebAudioWrapper = X_EventDispatcher[ 'inherits' ]( 'X.AV.WebAudioWrapper', X.Class.POOL_OBJECT, { @@ -67,23 +67,23 @@ if( X_Audio_WebAudio_context ){ } else if( audio ){ // TODO 当てにしていたaudioがclose 等した場合 - audio.proxy.listenOnce( 'canplaythrough', this, this._onBufferReady ); + 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' ); + 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 @@ -104,17 +104,17 @@ if( X_Audio_WebAudio_context ){ }; break; - case X_Event.CANCELED : + case X_EVENT_CANCELED : this.error = 1; - this.proxy.dispatch( 'aborted' ); + 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; }, @@ -124,21 +124,21 @@ if( X_Audio_WebAudio_context ){ 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.buffer = buffer; this.duration = buffer.duration * 1000; /* - this.proxy.asyncDispatch( 'loadedmetadata' ); - this.proxy.asyncDispatch( 'loadeddata' ); - this.proxy.asyncDispatch( 'canplay' ); - this.proxy.asyncDispatch( 'canplaythrough' ); + this.proxy[ 'asyncDispatch' ]( 'loadedmetadata' ); + this.proxy[ 'asyncDispatch' ]( 'loadeddata' ); + 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 ); + this.autoplay && X_Timer_once( 16, this, this.play ); console.log( 'WebAudio decoded!' ); }, @@ -147,7 +147,7 @@ if( X_Audio_WebAudio_context ){ 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(){ @@ -210,13 +210,13 @@ if( X_Audio_WebAudio_context ){ this.gainNode.gain.value = this.volume; // おかしい、stop 前に外していても呼ばれる、、、@Firefox33.1 - // 破棄された X.Callback が呼ばれて、obj._() でエラーになる。Firefox では、onended は使わない + // 破棄された X.Callback が呼ばれて、obj.proxy() でエラーになる。Firefox では、onended は使わない if( false && this.source.onended !== undefined ){ //console.log( '> use onended' ); this.source.onended = this._onended || ( this._onended = X_Callback_create( this, this._onEnded ) ); } else { - this._timerID && X.Timer.remove( this._timerID ); - this._timerID = X.Timer.once( end - begin, this, this._onEnded ); + this._timerID && X_Timer_remove( this._timerID ); + this._timerID = X_Timer_once( end - begin, this, this._onEnded ); }; if( this.source.start ){ @@ -229,7 +229,7 @@ if( X_Audio_WebAudio_context ){ 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 ); + this._interval = this._interval || X_Timer_add( 1000, 0, this, this._onInterval ); }, _onInterval : function(){ @@ -237,7 +237,7 @@ if( X_Audio_WebAudio_context ){ delete this._interval; return X_Callback_UN_LISTEN; }; - this.proxy.dispatch( X_Event.MEDIA_PLAYING ); + this.proxy[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); }, _onEnded : function(){ @@ -254,20 +254,20 @@ if( X_Audio_WebAudio_context ){ if( time < 0 ){ 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 ); + 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 ); }; }; }, @@ -279,7 +279,7 @@ if( X_Audio_WebAudio_context ){ this.seekTime = this.state().currentTime; - this._timerID && X.Timer.remove( this._timerID ); + this._timerID && X_Timer_remove( this._timerID ); delete this._timerID; delete this.playing; @@ -331,7 +331,7 @@ if( X_Audio_WebAudio_context ){ // detect : function( proxy, source, ext ){ - proxy.asyncDispatch( { type : X_Event.COMPLETE, canPlay : X_Audio_codecs[ ext ] } ); + proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : X_Audio_codecs[ ext ] } ); }, klass : X_Audio_WebAudioWrapper