OSDN Git Service

Version 0.6.121, iScroll5 is working on iPhone touch 1G, update X.Audio.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 01_XWebAudio.js
index abd163b..84216ed 100644 (file)
@@ -32,7 +32,7 @@ if( X_Audio_WebAudio_context ){
                        loopEndTime     : -1,
                        seekTime        : -1,
                        duration        : 0,
-                       
+
                        playing         : false,
                        error           : 0,                    
                        loop            : false,
@@ -57,9 +57,8 @@ if( X_Audio_WebAudio_context ){
                        Constructor : function( proxy, url, option ){
                                var audio = X_Audio_WebAudio_getBuffer( url );
                                
-                               this.url = url;
-                               this.closed = false;
                                this.proxy  = proxy;
+                               this.url    = url;
                                
                                X_AudioWrapper_updateStates( this, option );
                                
@@ -111,7 +110,7 @@ if( X_Audio_WebAudio_context ){
 
                                        case X.Event.COMPLETE :
                                                this.error = 2;                         
-                                               this.proxy.asyncDispatch( { type : '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 );
@@ -124,17 +123,19 @@ if( X_Audio_WebAudio_context ){
                                        this.onDecodeSuccess && this._onDecodeComplete();
                                        
                        if ( !buffer ) {
-                           this.proxy.asyncDispatch( { type : '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( X.Event.READY );
                        
                        this.autoplay && X.Timer.once( 16, this, this.play );
                        
@@ -145,7 +146,7 @@ if( X_Audio_WebAudio_context ){
                                        console.log( 'WebAudio decode error!' );
                                        this._onDecodeComplete();
                                        this.error = 3;
-                                       this.proxy.asyncDispatch( { type : 'error', message : 'decode error' } );
+                                       this.proxy.asyncDispatch( { type : X.Event.ERROR, message : 'decode error' } );
                                },
                                
                                _onDecodeComplete : function(){
@@ -235,7 +236,7 @@ if( X_Audio_WebAudio_context ){
                                                delete this._interval;
                                                return X_Callback_UN_LISTEN;
                                        };
-                                       this.proxy.dispatch( 'timeupdate' );
+                                       this.proxy.dispatch( X.Event.MEDIA_PLAYING );
                                },
                                                
                                _onEnded : function(){
@@ -257,13 +258,14 @@ if( X_Audio_WebAudio_context ){
                                };
                                
                                if( this.loop ){
-                                       if( !( this.proxy.dispatch( 'looped' ) & 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.play();
-                                       };
+                                       };
                                } else {
                                        this.pause();
-                                       this.proxy.dispatch( 'ended' );
+                                       this.proxy.dispatch( X.Event.MEDIA_ENDED );
                                };
                            };
                                },
@@ -319,18 +321,18 @@ if( X_Audio_WebAudio_context ){
 
                }
        );
-       
+
+
        X_Audio_BACKENDS.push(
                {
                        backendName : 'Web Audio',
 
                        // 
                        detect : function( proxy, source, ext ){
-                               proxy.asyncDispatch( X_Audio_codecs[ ext ] ? 'support' : 'nosupport' );
+                               proxy.asyncDispatch( X_Audio_codecs[ ext ] ? X_Audio_CAN_PLAY : X_Audio_NOT_PLAY );
                        },
                        
                        klass : X_Audio_WebAudioWrapper
                }
        );
-
 };