OSDN Git Service

Version 0.6.115, fix X.Class & X.Node.Selector for Opera Mobile 12, fix X.Audio.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 01_XWebAudio.js
index 07f4659..f7a5444 100644 (file)
@@ -32,6 +32,7 @@ if( X_Audio_WebAudio_context ){
                        error           : 0,                    
                        loop            : false,
                        looped          : false,
+                       autoplay        : false,
                        volume          : 0.5,
                                                
                        _startTime      : 0,
@@ -79,6 +80,7 @@ if( X_Audio_WebAudio_context ){
                                                return;
                                        
                                        case X.Event.SUCCESS :
+                                               console.log( 'WebAudio xhr success! ' + !!X_Audio_WebAudio_context.decodeAudioData );
                                        // TODO 旧api
                                        // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Porting_webkitAudioContext_code_to_standards_based_AudioContext
                                                if( X_Audio_WebAudio_context.decodeAudioData ){
@@ -105,6 +107,8 @@ if( X_Audio_WebAudio_context ){
                        },
                        
                                _onDecodeSuccess : function( buffer ){
+                                       console.log( 'WebAudio decode success!' );
+                                       
                                        this.onDecodeSuccess && this._onDecodeComplete();
                                        
                        if ( !buffer ) {
@@ -119,9 +123,14 @@ if( X_Audio_WebAudio_context ){
                        this.proxy.asyncDispatch( 'loadeddata' );
                        this.proxy.asyncDispatch( 'canplay' );
                        this.proxy.asyncDispatch( 'canplaythrough' );
+                       
+                       this.autoplay && X.Timer.once( 16, this, this.play );
+                       
+                       console.log( 'WebAudio decoded!' );
                                },
                                
                                _onDecodeError : function(){
+                                       console.log( 'WebAudio decode error!' );
                                        this._onDecodeComplete();
                                        this.error = 3;
                                        this.proxy.asyncDispatch( { type : 'error', message : 'decode error' } );
@@ -165,7 +174,10 @@ if( X_Audio_WebAudio_context ){
                        play : function(){
                                var begin, end;
                                
-                   if( !this.buffer ) return this;
+                   if( !this.buffer ){
+                       this.autoplay = true;
+                       return;
+                   };
                                
                                end   = X_AudioWrapper_getEndTime( this );
                                begin = X_AudioWrapper_getStartTime( this, end, true );