OSDN Git Service

Version 0.6.169, add doc comment.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 01_XWebAudio.js
index 66571d1..e8fd81b 100644 (file)
@@ -3,7 +3,8 @@ var X_Audio_WebAudio_context = !X_UA[ 'iPhone_4s' ]  && !X_UA[ 'iPad_2Mini1' ]
                                                                !( X_UA[ 'Gecko' ] && X_UA[ 'Android' ] ) &&
                                                                ( window.AudioContext || window.webkitAudioContext ),
        X_Audio_BUFFER_LIST      = [],
-       X_Audio_WebAudioWrapper;
+       X_Audio_WebAudioWrapper,
+       X_Audio_BufferLoader;
 
 /*
  * iPhone 4s 以下、iPad2以下、iPad mini 1以下, iPod touch 4G 以下は不可
@@ -52,8 +53,8 @@ if( X_Audio_WebAudio_context ){
                                                } else
                                                if( X_Audio_WebAudio_context.decodeAudioData ){
                                                        X_Audio_WebAudio_context.decodeAudioData( e.response,
-                                                               this.onDecodeSuccess = X_Callback_create( this, this._onDecodeSuccess ),
-                                                               this.onDecodeError   = X_Callback_create( this, this._onDecodeError ) );
+                                                               this.onDecodeSuccess = X_Closure_create( this, this._onDecodeSuccess ),
+                                                               this.onDecodeError   = X_Closure_create( this, this._onDecodeError ) );
                                                } else {
                                                        this._onDecodeSuccess( X_Audio_WebAudio_context.createBuffer( e.response, false ) );
                                                };
@@ -94,9 +95,9 @@ if( X_Audio_WebAudio_context ){
                                },
                                
                                _onDecodeComplete : function(){
-                                       X_Callback_correct( this.onDecodeSuccess );
+                                       X_Closure_correct( this.onDecodeSuccess );
                                        delete this.onDecodeSuccess;
-                                       X_Callback_correct( this.onDecodeError );
+                                       X_Closure_correct( this.onDecodeError );
                                        delete this.onDecodeError;
                                },
                        
@@ -155,7 +156,7 @@ if( X_Audio_WebAudio_context ){
                                
                                this.setState( option );
                                
-                               this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE, X_WebAudio_handleEvent );
+                               this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE, this.onKill );
                                
                                if( loader.buffer || loader.error ){
                                        this._onLoadBufferComplete();
@@ -163,6 +164,20 @@ if( X_Audio_WebAudio_context ){
                                        loader[ 'listenOnce' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete );
                                };
                        },
+                       
+                       onKill : function(){
+                               this.loader[ 'unlisten' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete )
+                                       .unregister( this );
+
+                               delete this.buffer;
+                               
+                               this.playing  && this.actualPause();
+                   this.source   && this._sourceDispose();
+       
+                   this._onended && X_Closure_correct( this._onended );        
+       
+                   this.gainNode && this.gainNode.disconnect();
+                       },
                                _onLoadBufferComplete : function( e ){
                                        var loader = this.loader,
                                                buffer = loader.buffer;
@@ -220,7 +235,7 @@ if( X_Audio_WebAudio_context ){
                    // 破棄された 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 ) );
+                       this.source.onended = this._onended || ( this._onended = X_Closure_create( this, this._onEnded ) );
                 } else {
                        this._timerID && X_Timer_remove( this._timerID );
                                        this._timerID = X_Timer_once( end - begin, this, this._onEnded );
@@ -248,7 +263,7 @@ if( X_Audio_WebAudio_context ){
                                _onInterval : function(){
                                        if( !this.playing ){
                                                delete this._interval;
-                                               return X_Callback_UN_LISTEN;
+                                               return X_CALLBACK_UN_LISTEN;
                                        };
                                        this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );
                                },
@@ -273,7 +288,7 @@ if( X_Audio_WebAudio_context ){
                                };
                                
                                if( this.autoLoop ){
-                                       if( !( this.target[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_Callback_PREVENT_DEFAULT ) ){
+                                       if( !( this.target[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){
                                                this.looped = true;
                                                this.target[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED );
                                                this.actualPlay();
@@ -320,25 +335,6 @@ if( X_Audio_WebAudio_context ){
                }
        );
 
-       function X_WebAudio_handleEvent( e ){
-               switch( e.type ){
-
-                       case X_EVENT_KILL_INSTANCE :
-                               this.loader[ 'unlisten' ]( X_EVENT_COMPLETE, this, this._onLoadBufferComplete )
-                                       .unregister( this );
-
-                               delete this.buffer;
-                               
-                               this.playing  && this.actualPause();
-                   this.source   && this._sourceDispose();
-       
-                   this._onended && X_Callback_correct( this._onended );       
-       
-                   this.gainNode && this.gainNode.disconnect();
-                               break;
-               };
-       };
-
        /*
         * http://qiita.com/sou/items/5688d4e7d3a37b4e2ff1
         * L-01F 等の一部端末で Web Audio API の再生結果に特定条件下でノイズが混ざることがある。
@@ -352,6 +348,8 @@ if( X_Audio_WebAudio_context ){
                {
                        backendName : 'Web Audio',
 
+                       canPlay : {}, // TODO HTMLAudio と同じ
+
                        // 
                        detect : function( proxy, source, ext ){
                                proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : X_Audio_codecs[ ext ] } );