OSDN Git Service

Version 0.6.204, bug fixes X.UA, update X.Util.Window.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 01_XWebAudio.js
index 47026ef..5d7124e 100644 (file)
@@ -1,8 +1,8 @@
 var X_Audio_constructor = 3.1 <= X_UA[ 'Safari' ] && X_UA[ 'Safari' ] < 4 ?
                                                                function( s, a ){
-                                                                       a = document.createElement( 'audio' );
-                                                                       a.src = s;
-                                                                       a.load();
+                                                                       //a = document.createElement( 'audio' );
+                                                                       //a.src = s;
+                                                                       //a.load();
                                                                        return a;
                                                                } :
                                                // Android1.6 + MobileOpera12 HTMLAudio はいるが呼ぶとクラッシュする
@@ -82,12 +82,17 @@ var X_WebAudio_context      =       // 4s 以下ではない iPad 2G または iPad mi
                                                                !X_UA[ 'iPhone_4s' ]  && !X_UA[ 'iPad_2Mini1' ]  && !X_UA[ 'iPod_4' ]  &&
                                                                // Android2 + Gecko で WebAudio が極めて不安定
                                                                !( X_UA[ 'Fennec' ] && X_UA[ 'Android' ] < 3 ) &&
+                                                               // AOSP でも WebAudio を不完全に実装するものがある, touch の有無も不明のため一律に切ってしまう
+                                                               !X_UA[ 'AOSP' ] && !( X_UA[ 'ChromeWV' ] < 5 ) &&
+                                                               // Blink HTMLAudio 調査用
+                                                               //!X_UA[ 'Blink' ] &&
                                                                // Firefox40.0.5 + Windows8 で音声が途中から鳴らなくなる
                                                                // Firefox41.0.1 + Windows8 で音声が途中から鳴らなくなる
-                                                               !( 40 <= X_UA[ 'Gecko' ] && X_UA[ 'Gecko' ] < 42 && X_UA[ 'Windows' ] ) &&
+                                                               !( 40 <= X_UA[ 'Gecko' ] && X_UA[ 'Gecko' ] < 44 && X_UA[ 'Windows' ] ) &&
                                                                ( window[ 'AudioContext' ] || window[ 'webkitAudioContext' ] ),
        X_WebAudio_BUFFER_LIST  = [],
        X_WebAudio_need1stTouch = X_UA[ 'iOS' ],
+       X_WebAudio_touchState   = X_WebAudio_need1stTouch,
        X_WebAudio,
        X_WebAudio_BufferLoader,
        X_WebAudio_fpsFix;
@@ -122,9 +127,13 @@ if( X_WebAudio_context ){
                        },
                        
                        handleEvent : function( e ){
+                               var i, l;
+                               
                                switch( e.type ){
                                        case X_EVENT_PROGRESS :
-                                               this[ 'dispatch' ]( { type : 'progress', 'percent' : e[ 'percent' ] } );
+                                               for( i = 0, l = this.webAudioList.length; i < l; ++i ){
+                                                       this.webAudioList[ i ][ 'dispatch' ]( { type : X_EVENT_PROGRESS, 'percent' : e[ 'percent' ] } );
+                                               };
                                                return;
                                        
                                        case X_EVENT_SUCCESS :
@@ -191,7 +200,7 @@ if( X_WebAudio_context ){
                                        i    = list.indexOf( webAudio );
                                if( 0 < i ){
                                        list.splice( i, 1 );
-                                       if( list.length ){
+                                       if( !list.length ){
                                                this.xhr && this.xhr[ 'kill' ]();
                                                this[ 'kill' ]();
                                        };
@@ -295,12 +304,7 @@ if( X_WebAudio_context ){
                        this.audioBuffer = buffer;
                        this.duration    = buffer.duration * 1000;
 
-                                       this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY );
-                       
-                       console.log( 'WebAudio buffer ready' );
-                       
-                       this.autoplay && !X_WebAudio_need1stTouch && X_Timer_once( 16, this, this.actualPlay );
-                                       
+                                       this.disatcher[ 'asyncDispatch' ]( X_WebAudio_touchState ? X_EVENT_MEDIA_TOUCH_FOR_LOAD : X_EVENT_READY );
                                },
                        
                        actualPlay : function(){
@@ -309,17 +313,21 @@ if( X_WebAudio_context ){
                                console.log( '[WebAudio] play abuf:' + !!this.audioBuffer );
                                
                    if( !this.audioBuffer ){
-                       this.autoplay = true;
+                       this._playReserved = true;
                        return;
                    };
                                
-                               if( X_WebAudio_need1stTouch ){
+                               if( X_WebAudio_touchState ){
                                        e = X_EventDispatcher_CURRENT_EVENTS[ X_EventDispatcher_CURRENT_EVENTS.length - 1 ];
                                        if( !e || !e[ 'pointerType' ] ){
-                                               alert( 'タッチイベント以外での play! ' + ( e ? e.type : '' ) );
+                                               // alert( 'タッチイベント以外での play! ' + ( e ? e.type : '' ) );
                                                return;
                                        };
+                                       // http://qiita.com/uupaa/items/e5856e3cb2a9fc8c5507
+                                       // iOS9 + touchstart で呼んでいた場合、 X_ViewPort['listenOnce']('pointerup',this,this.actualPlay())
+                                       this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY );
                                };
+                               X_WebAudio_touchState = false;
                                
                                end   = X_Audio_getEndTime( this );
                                begin = X_Audio_getStartTime( this, end, true );
@@ -363,7 +371,7 @@ if( X_WebAudio_context ){
                        
                                _sourceDispose : function(){
                            this.bufferSource.disconnect();
-                           delete this.bufferSource.onended;
+                           //delete this.bufferSource.onended;
                            delete this.bufferSource;
                        },
 
@@ -408,18 +416,14 @@ if( X_WebAudio_context ){
                                },
                        
                        actualPause : function(){
-                               //if( !this.playing ) return this;
-                               
                                console.log( '[WebAudio] pause' );
                                
-                               this.seekTime = this.getActualCurrentTime();
-                               
                    this._timerID && X_Timer_remove( this._timerID );
                                delete this._timerID;
                                delete this.playing;
 
                    if( this.bufferSource ){
-                       if( this.bufferSource.onended ) delete this.bufferSource.onended;
+                       //if( this.bufferSource.onended ) delete this.bufferSource.onended;
                        
                        this.bufferSource.stop ? 
                                this.bufferSource.stop( 0 ) : this.bufferSource[ 'noteOff' ]( 0 );