X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F07_audio%2F02_XHTMLAudio.js;h=7acc1e01040c20f6aec0369de8d45021f72ad7ef;hb=54eba266c29baf743f6ac67942a2788cd697b12d;hp=786f343ba086d2fe5e04e08d2ec0b4562f8a6f54;hpb=3c07e12e13272820cedf983e0d9fe46e5f0a4bd9;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/07_audio/02_XHTMLAudio.js b/0.6.x/js/07_audio/02_XHTMLAudio.js index 786f343..7acc1e0 100644 --- a/0.6.x/js/07_audio/02_XHTMLAudio.js +++ b/0.6.x/js/07_audio/02_XHTMLAudio.js @@ -65,12 +65,15 @@ var X_HTMLAudio_pauseFix = 12 <= X_UA[ 'Opera' ] && 0 < ' XP XPSP2 2003|XP64'.indexOf( X_UA[ 'Windows' ] ), // XP + Opera12 のみ? X_HTMLAudio_need1stTouch = X_UA[ 'iOS' ] || 4.2 <= X_UA[ 'AOSP' ] || X_UA[ 'ChromeWV' ] || X_UA[ 'WinPhone' ] || ( X_UA[ 'Blink' ] && X_UA[ 'Android' ] ), + + X_HTMLAudio_playTrigger = ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ) ? 'canplay' : X_UA[ 'iOS' ] ? 'suspend' : X_UA[ 'Blink' ] < 32 ? 'stalled' : 'canplaythrough', + + X_HTMLAudio_durationFix = X_UA[ 'iOS' ] || X_UA[ 'ChromeWV' ] || ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ) || + ( X_UA[ 'Windows' ] && 12 <= X_UA[ 'Opera' ] ) || ( X_UA[ 'Blink' ] < 36 && X_UA[ 'Android' ] ), + + X_HTMLAudio_shortPlayFix = X_UA[ 'AOSP' ], - X_HTMLAudio_playTrigger = ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ) ? 'canplay' : X_UA[ 'iOS' ] ? 'suspend' : X_UA[ 'Blink' ] ? 'stalled' : 'canplaythrough', - - X_HTMLAudio_durationFix = X_UA[ 'iOS' ] || X_UA[ 'ChromeWV' ] || ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ) || ( X_UA[ 'Windows' ] && 12 <= X_UA[ 'Opera' ] ), - - X_HTMLAudio_shortPlayFix = X_UA[ 'AOSP' ]; // Android 4.1.1 でも遭遇 + X_HTMLAudio_progressEnabled = !( X_UA[ 'Opera' ] && X_UA[ 'Android' ] ) && !( X_UA[ 'WinPhones' ] && X_UA[ 'IE9' ] ); // Android 4.1.1 でも遭遇 if( X_Audio_constructor ){ @@ -78,10 +81,9 @@ if( X_Audio_constructor ){ 'X.HTMLAudio', X_Class.POOL_OBJECT, { - _closed : true, - // 1: canplaythrought|timeupdateに達している、またはdurationFixが終了している // 2: READY イベント発火済 + // 3: 1, 2 が済 _readyState : 0, _src : '', @@ -111,7 +113,6 @@ if( X_Audio_constructor ){ var raw; this.disatcher = disatcher || this; - this._closed = false; this._src = source; if( X_HTMLAudio_shortPlayFix ){ @@ -192,14 +193,13 @@ if( X_Audio_constructor ){ ready, eventType, duration, end, now; - if( this._closed ) return; + if( !raw ) return; //e.type !== 'timeupdate' && console.log( ' > ' + e.type ); switch( e.type ){ case X_EVENT_KILL_INSTANCE : - delete this._closed; this.playing && this.actualPause(); // 【javascript】モバイル向けブラウザでも音を鳴らしたい【WebAudio】 @@ -217,7 +217,7 @@ if( X_Audio_constructor ){ // console.log( e.loaded + ' ' + e.total * 100 + '%' ); // iem9 で常に0 raw.networkState; // opera Android 12 で buffered.end() へのアクセスはエラー try catch も無効、iem9 は常に end(0) = 0 - if( !( X_UA[ 'Opera' ] && X_UA[ 'Android' ] ) && !( X_UA[ 'WinPhones' ] && X_UA[ 'IE9' ] ) && this.duration ){ + if( X_HTMLAudio_progressEnabled && this.duration && this._readyState < 3 ){ buf = raw.buffered; time = 0; for( i = 0, l = buf.length; i < l; ++i ){ @@ -233,7 +233,7 @@ if( X_Audio_constructor ){ this._readyState |= 1; }; case 'canplay' : // 今すぐに再生を再開できるが、バッファリングが不十分でコンテンツを最後まで表示できないと予測している場合に発生 - if( this._durationFixPhase === 1 && !X_HTMLAudio_need1stTouch ){ + if( this._durationFixPhase === 1 && !X_HTMLAudio_need1stTouch ){ // PC Opera12 用 durationFix this._durationFixPhase = 2; this.actualPlay(); raw.currentTime = 0; // Win8 + Opera12 で必要 @@ -324,7 +324,8 @@ if( X_Audio_constructor ){ }; // duration は Infinity, NaN, 0 の場合があるため、これを除外する - if( 0 < duration && X_Type_isFinite( duration ) ){ + // chrome18 for Android は duration = 100 の間はシークができない? 28 は可能 + if( 0 < duration && X_Type_isFinite( duration ) && duration !== 100 ){ this.duration = duration * 1000; if( this._durationFixPhase === 4 ){ @@ -333,7 +334,6 @@ if( X_Audio_constructor ){ if( this.autoplay || this._playReserved ){ console.log( '☆ 再生 <- DurationFix の終了' ); - delete this._playReserved; this.actualPlay(); } else if( X_HTMLAudio_pauseFix ){ @@ -367,7 +367,7 @@ if( X_Audio_constructor ){ }; } else if( this._readyState === 1 && this.duration ){ - this._readyState = 3; + this._readyState |= 2; this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY ); console.log( '> Audio Loaded!! ' + e.type + ' d:' + ( this.duration | 0 ) ); } else @@ -380,13 +380,20 @@ if( X_Audio_constructor ){ var raw = this[ '_rawObject' ], e, begin, end; - if( this._closed ) return; + if( !raw ) return; - if( !raw.src ){ // X_HTMLAudio_pauseFix によって src が空になっている - console.log( '○ 削除された audio.src の復帰' ); - raw.src = this._src; - return; - }; + this._playReserved = true; + + if( X_HTMLAudio_pauseFix ){ + if( !raw.src ){ // X_HTMLAudio_pauseFix によって src が空になっている + console.log( '○ 削除された audio.src の復帰' ); + raw.src = this._src; + return; + }; + if( this._durationFixPhase < 2 ){ + return; + }; + }; if( this._touchState === 2 ){ e = X_EventDispatcher_CURRENT_EVENTS[ X_EventDispatcher_CURRENT_EVENTS.length - 1 ]; @@ -397,10 +404,11 @@ if( X_Audio_constructor ){ this._touchState = 3; } else if( this._readyState !== 3 && this._durationFixPhase < 2 ){ - this._playReserved = true; return; }; + delete this._playReserved; + if( this._durationFixPhase & 3 ){ // 1 or 2 console.log( '▲ DurationFix の開始' ); this._durationFixPhase = 4; @@ -432,7 +440,6 @@ if( X_Audio_constructor ){ } else if( X_HTMLAudio_needPlayForSeek || forcePlay ){ raw.play(); - //console.log( '[HTMLAudio] currentTime より先.' ); }; //http://himaxoff.blog111.fc2.com/blog-entry-97.html