From: itozyun Date: Fri, 2 Oct 2015 07:00:43 +0000 (+0900) Subject: Version 0.6.173, add OS detection to X.UA, fix X.Timer @Chrome & X.Audio. X-Git-Url: http://git.osdn.jp/view?p=pettanr%2FclientJs.git;a=commitdiff_plain;h=ecfded871abcf085bbc2b862352232190b87fd27 Version 0.6.173, add OS detection to X.UA, fix X.Timer @Chrome & X.Audio. --- diff --git a/0.6.x/js/01_core/02_XUA.js b/0.6.x/js/01_core/02_XUA.js index fafe846..8302b97 100644 --- a/0.6.x/js/01_core/02_XUA.js +++ b/0.6.x/js/01_core/02_XUA.js @@ -136,26 +136,65 @@ var X_UA = X[ 'UA' ] = {}, X_UA[ 'webOS' ] = true; // webOS } else if( sys.indexOf( 'Win' ) + 1 ){ - console.log( 'Win' ); - /** - * @alias X.UA.Windows - * @type {boolean} - */ - X_UA[ 'Windows' ] = true; + switch( sys ){ + case 'WinCE' : + /** + * @alias X.UA.WinCE + * @type {boolean} + */ + X_UA[ sys ] = true; + break; case 'Win16' : case 'Win32' : case 'Win64' : - case 'WinCE' : /** * @alias X.UA.Win16 * @alias X.UA.Win32 * @alias X.UA.Win64 - * @alias X.UA.WinCE * @type {boolean} */ X_UA[ sys ] = true; + + if( v = dav.split( 'Windows NT 10' )[ 1 ] ){ + switch( v.substr( 0, 2 ) ){ + case '.0' : v = 10; break; + default : v = '?'; + }; + } else + if( v = dav.split( 'Windows NT ' )[ 1 ] ){ + switch( v.substr( 0, 3 ) ){ + case '6.3' : v = 8.1; break; + case '6.2' : v = 8; break; + case '6.1' : v = 7; break; + case '6.0' : v = 'Vista'; break; + case '5.2' : v = '2003|XP64'; break; + case '5.1' : v = v.indexOf( '5.1; SV1' ) ? 'XP' : 'XPSP2'; break; + case '5.0' : v = v.indexOf( '5.01' ) ? 2000 : '2kSP1'; break; + case '4.0' : v = 'NT'; break; + default : v = '?'; + }; + } else + if( v = dav.split( 'Windows ' )[ 1 ] ){ + switch( v.substr( 0, 2 ) ){ + case '98' : v = v.indexOf( '98; Win 9x 4.90' ) ? '98|98SE' : 'ME'; break; + case '95' : v = 95; break; + case '3.' : v = parseFloat( v ); break; + default : v = '?'; + }; + } else { + v = '?'; + }; + + /** + * 10, 8.1, 8, 7, Vista, 2003|XP64, XPSP2, XP, 2kSP1, 2000, ME, 98|98SE, 95, ? + * @alias X.UA.Windows + * @type {number|string} + */ + X_UA[ 'Windows' ] = v; + break; }; + // winRT } else if( sys.indexOf( 'Mac' ) + 1 ){ diff --git a/0.6.x/js/01_core/04_XObject.js b/0.6.x/js/01_core/04_XObject.js index 5791535..9ee8197 100644 --- a/0.6.x/js/01_core/04_XObject.js +++ b/0.6.x/js/01_core/04_XObject.js @@ -40,8 +40,9 @@ X[ 'Object' ] = { 'isEmpty' : X_Object_isEmpty, - 'inObject' : X_Object_inObject + 'inObject' : X_Object_inObject, + 'find' : X_Object_find // TODO hasOwnProperty }; @@ -152,3 +153,20 @@ function X_Object_isEmpty( v ){ return true; }; +/** + * obj に対し、selector で示した値を返す。メンバを辿れなかった場合、undefined が返る。 + * @alias X.Object.find + * @param {object} obj + * @param {string} selector + * @return {*} + */ +function X_Object_find( obj, selector ){ + var selectors = selector.split( '>' ); + + for( ; selector = selectors.shift(); ){ + obj = obj[ selector ]; + if( !obj ) return; + }; + return obj; +}; + diff --git a/0.6.x/js/01_core/16_XTimer.js b/0.6.x/js/01_core/16_XTimer.js index faa9031..744a33b 100644 --- a/0.6.x/js/01_core/16_XTimer.js +++ b/0.6.x/js/01_core/16_XTimer.js @@ -388,9 +388,14 @@ function X_Timer_update(){ }; }; -// 大きい -> 小さい +// 小さい -> 大きい、 同値の場合 uid の小さいものが先 +// http://jsfiddle.net/warby_/X8YUZ/ Chrome で return が 0 の場合の挙動が他のブラウザと異なる function X_Timer_compareQueue( a, b ){ - return a.last < b.last ? -1 : a.last === b.last ? 0 : 1; + if( a.last === b.last ){ // Chrome のみ + return a.uid - b.uid; + }; + return a.last - b.last; + // return a.last <= b.last ? -1 : 1; //a.last === b.last ? 0 : 1; }; // http://havelog.ayumusato.com/develop/javascript/e528-ios6_scrolling_timer_notcall.html diff --git a/0.6.x/js/01_core/21_XViewPort.js b/0.6.x/js/01_core/21_XViewPort.js index aa8cdc3..8d3bca1 100644 --- a/0.6.x/js/01_core/21_XViewPort.js +++ b/0.6.x/js/01_core/21_XViewPort.js @@ -87,6 +87,8 @@ X_ViewPort = X_Class_override( X_ViewPort_activeTimerID = X_Timer_once( 16, X_ViewPort_changeFocus ); return X_CALLBACK_PREVENT_DEFAULT | X_CALLBACK_STOP_PROPAGATION; }; + // 他の要素のfocusout がバブルアップしてきたもの + if( e.target !== X_ViewPort_document ) break; case 'pagehide' : active = true; case 'focus' : diff --git a/0.6.x/js/02_dom/20_XNode.js b/0.6.x/js/02_dom/20_XNode.js index b7f8ce9..e7d85ec 100644 --- a/0.6.x/js/02_dom/20_XNode.js +++ b/0.6.x/js/02_dom/20_XNode.js @@ -787,8 +787,7 @@ function X_Node_remove(){ this[ '_xnodes' ] && X_Node_toggleInTreeFlag( this[ '_xnodes' ], false ); if( X_UA_DOM.IE4 ){ - elm = this[ '_rawObject' ] || X_Node__ie4getRawNode( this ); - if( elm ){ + if( elm = this[ '_rawObject' ] || X_Node__ie4getRawNode( this ) ){ X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this; X_Node_reserveUpdate(); } else @@ -802,6 +801,14 @@ function X_Node_remove(){ X_Node_reserveUpdate(); }; }; + } else { + if( !X_UA_DOM.IE4 ){ + elm = this[ '_rawObject' ]; + if( elm && elm.parentNode && elm.parentNode.tagName ){ + X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this; + X_Node_reserveUpdate(); + }; + }; }; return this; }; diff --git a/0.6.x/js/03_plugin/00_XPlugin.js b/0.6.x/js/03_plugin/00_XPlugin.js index 7bd7e97..ed4619e 100644 --- a/0.6.x/js/03_plugin/00_XPlugin.js +++ b/0.6.x/js/03_plugin/00_XPlugin.js @@ -17,8 +17,7 @@ * flash player 11.1, Win2k, Android 2.x-4.x */ var X_Pulgin_FLASH_VERSION = - !X_UA[ 'IE' ] && navigator.plugins[ 'Shockwave Flash' ] ? - parseFloat( navigator.plugins[ 'Shockwave Flash' ].version ) : + !X_UA[ 'IE' ] || !X_UA[ 'ActiveX' ] ? parseFloat( X_Object_find( navigator, 'plugins>Shockwave Flash>version' ) || 0 ) : !X_UA[ 'IE4' ] && !X_UA[ 'IE5' ] && X_UA[ 'ActiveX' ] ? (function(){ var obj = eval( 'var a,e;try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(e){}a' ), ver = obj && obj[ 'GetVariable' ]( '$version' ).split( ' ' ).join( '.' ); @@ -28,16 +27,13 @@ var X_Pulgin_FLASH_VERSION = X_Pulgin_FLASH_ENABLED = X_UA[ 'ActiveX' ] ? !!X_Pulgin_FLASH_VERSION : - navigator.mimeTypes && - navigator.mimeTypes[ 'application/x-shockwave-flash' ] && - navigator.mimeTypes[ 'application/x-shockwave-flash' ].enabledPlugin, + X_Object_find( navigator, 'mimeTypes>application/x-shockwave-flash>enabledPlugin' ), /* - * ie11 の 互換モード(8,7)では、Silverlight が動作しない? + * ie11 の 互換モード(8,7)では、Silverlight が動作しない? */ X_Pulgin_SILVER_LIGHT_VERSION = - !X_UA[ 'IE' ] && navigator.plugins[ 'Silverlight Plug-In' ] ? - parseFloat( navigator.plugins[ 'Silverlight Plug-In' ].version ) : + !X_UA[ 'IE' ] || !X_UA[ 'ActiveX' ] ? parseFloat( X_Object_find( navigator, 'plugins>Silverlight Plug-In>version' ) || 0 ) : X_UA[ 'ActiveX' ] && 6 <= X_UA[ 'IE' ] ? (function(){ return eval( 'var a,i=0;try{a=new ActiveXObject("AgControl.AgControl");for(i=5;i;--i)if(a.IsVersionSupported(i+".0"))break;}catch(e){i=0}i' ); })() : @@ -45,14 +41,12 @@ var X_Pulgin_FLASH_VERSION = X_Pulgin_SILVER_LIGHT_ENABLED = X_UA[ 'ActiveX' ] ? !!X_Pulgin_SILVER_LIGHT_VERSION : - navigator.mimeTypes && - navigator.mimeTypes[ 'application/x-silverlight' ] && - navigator.mimeTypes[ 'application/x-silverlight' ].enabledPlugin, + X_Object_find( navigator, 'mimeTypes>application/x-silverlight>enabledPlugin' ), //http://docs.unity3d.ru/Manual/Detecting%20the%20Unity%20Web%20Player%20using%20browser%20scripting.html X_Pulgin_UNITY_VERSION = - !X_UA[ 'IE' ] && navigator.plugins[ 'Unity Player' ] ? - parseFloat( navigator.plugins[ 'Unity Player' ].version ) : + !X_UA[ 'IE' ] || !X_UA[ 'ActiveX' ] ? + parseFloat( X_Object_find( navigator, 'plugins>Unity Player>version' ) || 0 ) : !X_UA[ 'IE4' ] && !X_UA[ 'IE5' ] && X_UA[ 'ActiveX' ] ? (function(){ var obj = eval( 'var a,e;try{a=new ActiveXObject("UnityWebPlayer.UnityWebPlayer.1")}catch(e){}a' ); return obj ? parseFloat( obj[ 'GetPluginVersion' ]() ) : 0; @@ -61,9 +55,7 @@ var X_Pulgin_FLASH_VERSION = X_Pulgin_UNITY_ENABLED = X_UA[ 'ActiveX' ] ? !!X_Pulgin_UNITY_VERSION : - navigator.mimeTypes && - navigator.mimeTypes[ 'application/vnd.unity' ] && - navigator.mimeTypes[ 'application/vnd.unity' ].enabledPlugin, + X_Object_find( navigator, 'mimeTypes>application/vnd.unity>enabledPlugin' ), X_Pulgin_GEARS_ENABLED = window.GearsFactory || @@ -71,11 +63,26 @@ var X_Pulgin_FLASH_VERSION = (function(){ return eval( 'var a,e;try{a=new ActiveXObject("Gears.Factory")}catch(e){}!!a' ); })() : - navigator.mimeTypes && - navigator.mimeTypes[ 'application/x-googlegears' ] && - navigator.mimeTypes[ 'application/x-googlegears' ].enabledPlugin + X_Object_find( navigator, 'mimeTypes>application/x-googlegears>enabledPlugin' ) ), + // QuickTime Plug-in 7.7.6 + /* + X_Pulgin_QUICKTIME_VERSION = + !X_UA[ 'IE' ] || !X_UA[ 'ActiveX' ] ? (function( plugins, k ){ + for( k in plugins ){ + if( k.indexOf( 'QuickTime' ) === 0 ) return parseFloat( k.substr( 18 ) ) || 0; + }; + return 0; + })( navigator.plugins ) : + !X_UA[ 'IE4' ] && !X_UA[ 'IE5' ] && X_UA[ 'ActiveX' ] ? (function(){ + var obj = eval( 'var a,e;try{a=new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1")}catch(e){}a' ), + ver = obj && obj[ 'QuickTimeVersion' ].toString( 16 ); + + return ver ? parseFloat( ver.substr( 0, 3 ) ) / 100 : 0; + })() : + 0, */ + X_Pulgin_VBS_ENABLED = X_UA[ 'Windows' ] && !X_UA[ 'WinCE' ] && X_UA[ 'IE' ] < 11; @@ -87,17 +94,19 @@ X[ 'Pulgin' ] = { 'Flash' : X_Pulgin_FLASH_VERSION, - 'FlashEnabled' : !!X_Pulgin_FLASH_ENABLED, + 'FlashEnabled' : X_Pulgin_FLASH_ENABLED, 'Silverlight' : X_Pulgin_SILVER_LIGHT_VERSION, - 'SilverlightEnabled' : !!X_Pulgin_SILVER_LIGHT_ENABLED, + 'SilverlightEnabled' : X_Pulgin_SILVER_LIGHT_ENABLED, 'Unity' : X_Pulgin_UNITY_VERSION, - 'UnityEnabled' : !!X_Pulgin_UNITY_ENABLED, + 'UnityEnabled' : X_Pulgin_UNITY_ENABLED, + + 'QuickTime' : X_Pulgin_QUICKTIME_VERSION, - 'GearsEnabled' : X_Pulgin_GEARS_ENABLED + 'GearsEnabled' : !!X_Pulgin_GEARS_ENABLED }; diff --git a/0.6.x/js/07_audio/00_XAudio.js b/0.6.x/js/07_audio/00_XAudio.js index 4086c18..584755e 100644 --- a/0.6.x/js/07_audio/00_XAudio.js +++ b/0.6.x/js/07_audio/00_XAudio.js @@ -275,6 +275,7 @@ var X_Audio_AbstractAudioBackend = X_EventDispatcher[ 'inherits' ]( 'startTime' : startTime, 'endTime' : endTime, 'loop' : loop, + 'looped' : false, 'loopStartTime' : loopStartTime, 'loopEndTime' : loopEndTime } ); @@ -444,7 +445,7 @@ var X_Audio_AbstractAudioBackend = X_EventDispatcher[ 'inherits' ]( X_AudioWrapper_getEndTime( this ) < this.seekTime// || //this.duration < this.endTime ){ - console.log( 'setState 0:' + this.startTime + ' -> ' + this.endTime + ' d:' + this.duration + ' 1:' + this.loopStartTime + ' -> ' + this.loopEndTime ); + console.log( 'setState 0:' + this.startTime + ' -> ' + this.endTime + ' looped:' + this.looped + ' 1:' + this.loopStartTime + ' -> ' + this.loopEndTime ); return; }; @@ -494,6 +495,7 @@ function X_AudioWrapper_timeStringToNumber( time ){ function X_AudioWrapper_getStartTime( audioWrapper, endTime, delSeekTime ){ var seek = audioWrapper.seekTime; + if( delSeekTime ) delete audioWrapper.seekTime; if( 0 <= seek ){ diff --git a/0.6.x/js/07_audio/01_XWebAudio.js b/0.6.x/js/07_audio/01_XWebAudio.js index 08eb781..6d63435 100644 --- a/0.6.x/js/07_audio/01_XWebAudio.js +++ b/0.6.x/js/07_audio/01_XWebAudio.js @@ -315,7 +315,7 @@ if( X_Audio_WebAudio_context ){ }, actualPause : function(){ - if( !this.playing ) return this; + //if( !this.playing ) return this; console.log( '[WebAudio] pause' ); diff --git a/0.6.x/js/07_audio/02_XHTMLAudio.js b/0.6.x/js/07_audio/02_XHTMLAudio.js index 0a8060d..2082a86 100644 --- a/0.6.x/js/07_audio/02_XHTMLAudio.js +++ b/0.6.x/js/07_audio/02_XHTMLAudio.js @@ -2,61 +2,93 @@ /* * original : uupaa-js HTML5Audio.js * https://code.google.com/p/uupaa-js/source/browse/trunk/0.8/src/Audio/HTML5Audio.js?r=568 + * + * Windows 版 Safari は QuickTime のインストールが必要 + * + * 1. iOS4(iPod 2G) で ended に達すると音が鳴らなくなる fix で解決 + * 2. iOS6(iPod 4G) で ended に達すると音が鳴らなくなる fix で頻度が改善 + * 3. WP7(IS12T) で最後の方にある音が鳴らない? mp3 cbr を使えばいい? 裏に回っても音が鳴り続ける + * 4. Android 3.x で ended に達すると音が鳴らなくなる -> リロード(audio.src='';audio.sr=src)で解決 + * 5. Android 2.x で ended に達すると音が鳴らなくなる -> リロード(audio.src='';audio.src=src;audio.load())でで解決 + * 6. Android 4.4.2- は ended に達した際に currentTime が変更できなくなり、リロードが必要になる */ -var X_Audio_HTMLAudio_playTrigger = +var X_HTMLAudio_playTrigger = 6 <= X_UA[ 'iOS' ] ? 'loadeddata' : X_UA[ 'iOS' ] < 5 ? 'stalled' : - X_UA[ 'iOS' ] ? 'suspend' : + X_UA[ 'iOS' ] ? 'suspend' : + X_UA[ 'Safari' ] < 4 ? 'canplaythrough' : X_UA[ 'AndroidChromeBrowser' ] ? 'canplaythrough' : // Android 2.3.5(SBM101SH) では stalled は発生しない,,, ので必ず loadeddata もチェックする X_UA[ 'AndroidBrowser' ] ? 'stalled' : X_UA[ 'OperaMobile' ] || X_UA[ 'OperaTablet' ] ? 'loadeddata' : 'loadeddata', //'canplay', - X_Audio_HTMLAudioWrapper, - X_Audio_constructor = window[ 'Audio' ] || window.HTMLAudioElement, - X_Audio_rawAudio, - // onended イベント時に再生を継続する場合、audio.play() を呼ぶ必要がある - X_Audio_HTMLAudioWrapper_needPlayOnended = !X_UA[ 'AndroidChromeBrowser' ] && X_UA[ 'AndroidBrowser' ], - // Opera Mobile 12 android4.4.4 & 2.3.5 は 2回目以降の currentTime へのセットで currentTime が更新されなくなるため、タイマーを使用する - X_Audio_HTMLAudioWrapper_currentTimeFix = !!X_UA[ 'OperaMobile' ] || !!X_UA[ 'OperaTablet' ], + X_HTMLAudio, + X_Audio_constructor = X_UA[ 'Safari' ] < 4 ? function(a){ a = document.createElement( 'audio' ); return a; } : window[ 'Audio' ] || window.HTMLAudioElement, + + // ended が発生しない timeupdate 内で play() を呼ぶ (未検証) 不具合確認は iOS4,6 + X_HTMLAudio_endedFixIOS = X_UA[ 'iOS' ] < 7, + // Android 2.3.5 で ended 時に audio.src='';audio.src=src;audio.load() を実施。 2.3.4 でも問題なし。 + X_HTMLAudio_endedFixAOSP2 = X_UA[ 'AndroidBrowser' ] < 3, + // Android 3.1 で ended 時に src='';src=src を実施。 + X_HTMLAudio_endedFixAOSP3 = !X_HTMLAudio_endedFixAOSP2 && X_UA[ 'AndroidBrowser' ] < 4, + // ended 時に play() を実施, currentTime が duration に張り付き更新されなければ src='';src=src を実施。 + X_HTMLAudio_endedFixAOSP4 = !X_UA[ 'AndroidChromeBrowser' ] && 4 <= X_UA[ 'AndroidBrowser' ], + + // Opera Mobile 12 は 2回目以降の currentTime へのセットで currentTime が更新されなくなるため、タイマーを使用する + X_HTMLAudio_currentTimeFix = !!X_UA[ 'OperaMobile' ] || !!X_UA[ 'OperaTablet' ], // Android1.6+MobileOpera12では無理っぽい、、、 - X_Audio_HTMLAudioWrapper_badOperaAndroid = X_Audio_HTMLAudioWrapper_currentTimeFix && X_UA[ 'Android' ] < 2, + X_HTMLAudio_badOperaAndroid = X_HTMLAudio_currentTimeFix && X_UA[ 'Android' ] < 2, - // 一方 Desktop の Opera12 は、loadeddata 等では duration が infinity で、再生後の durationchange 時に duration が判明する。 - // opera12 volume, mute の変更が2度目以降できない - // duration 判明後には currentTime によるシークと、現在時間の取得が可能になる。 - // canplay で play() durationchange で duration が取れたら loadedmetadata->loadeddata -> canplay する - // boombox.js に書いてあった currentTime の効かないブラウザってこいつのことみたい、、、 - // Opera12.17 Win32(XP) portable apps は勝手に再生が始まる、、、その際には timeupdate が発行されない、、、 iframe+image+audio で使わないときは破棄する、とか。 - // opera11、10.54 WinXP はまとも、、、 - // X_Audio_Sprite_handleEvent でも使用 - X_Audio_HTMLAudioWrapper_ieMobile9Fix = ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ), - X_Audio_HTMLAudioWrapper_durationFix = ( !X_Audio_HTMLAudioWrapper_currentTimeFix && 12 <= X_UA[ 'Opera' ] ) || X_UA[ 'AndroidChromeBrowser' ], - - X_Audio_HTMLAudioWrapper_shortPlayFix = X_UA[ 'AndroidBrowser' ] && X_UA[ 'AndroidWebkit' ] <= 534.3, // Android 4.1.1 でも遭遇(ただしm4a, mp3は優秀, oggはシークが乱れる) + X_HTMLAudio_volumeFix = X_UA[ 'Chrome' ], + /* + * win opera12 volume, mute の変更が2度目以降できない + */ + X_HTMLAudio_volumeEnabled = !( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ) && !X_UA[ 'Opera' ], + // Gecko PC + Android でseek時に再生がしばしば止まる問題の修正 + X_HTMLAudio_needPlayForSeek = X_UA[ 'Gecko' ], + // + X_HTMLAudio_pauseFix = ( X_UA[ 'Windows' ] && 12 <= X_UA[ 'Opera' ] && 0 < ' XP XPSP2 2003|XP64'.indexOf( X_UA[ 'Windows' ] ) ), // XP + Opera12 のみ? + /* + * durationFix + * duration が取得できるタイミングが遅くそれまでは infinity(PC Opera12), NaN(WP9), 0(AndroidBrowser Chrome 系) が入っている + * + * 1. touch が不要の場合、自動で再生を開始して duration を取得するまで再生する + * -> 取得後に pause or 通常再生 + * 2. touch が必要な場合、タッチイベント内の audio.play() で duration 取得 + * + * PC Opera12 + * 1. loadeddata 等では duration が infinity で、再生後の durationchange 時に duration が判明する + * 2. duration 判明後には currentTime によるシークと、現在時間の取得が可能になる。 + * 3. Opera12.17 Win32(XP) portable apps は勝手に再生が始まる、、、Win8+Opera では発生しない + * -> その際には timeupdate が発行されない、、、 iframe+image+audio で使わないときは破棄する、とか。 + * -> opera11、10.54 WinXP はまとも、、、 portable が怪しい?? + */ + X_HTMLAudio_need1stTouch = X_UA[ 'iOS' ] || X_UA[ 'AndroidChromeBrowser' ] || ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ), + X_HTMLAudio_durationFix = ( X_UA[ 'Windows' ] && 12 <= X_UA[ 'Opera' ] ) || X_UA[ 'AndroidChromeBrowser' ] || ( X_UA[ 'WinPhone' ] && X_UA[ 'IE9' ] ), + X_HTMLAudio_shortPlayFix = !X_UA[ 'AndroidChromeBrowser' ] && X_UA[ 'AndroidBrowser' ], // Android 4.1.1 でも遭遇(ただしm4a, mp3は優秀, oggはシークが乱れる) X_Audio_codecs; -if( X_Audio_constructor && !X_Audio_HTMLAudioWrapper_badOperaAndroid ){ +if( X_Audio_constructor && !X_HTMLAudio_badOperaAndroid ){ //http://himaxoff.blog111.fc2.com/blog-entry-97.html //引数なしで new Audio() とすると、Operaでエラーになるそうなので注意。 - X_Audio_rawAudio = new X_Audio_constructor( '' ); - + X_TEMP.rawAudio = new X_Audio_constructor( '' ); + // https://html5experts.jp/miyuki-baba/3766/ - // Chrome for Android31 で HE-AAC が低速再生されるバグ + // TODO Chrome for Android31 で HE-AAC が低速再生されるバグ // TODO Android4 標準ブラウザで ogg のシークが正しくない! - if( X_Audio_rawAudio.canPlayType ){ + if( X_TEMP.rawAudio.canPlayType ){ X_Audio_codecs = { - 'mp3' : X_Audio_rawAudio.canPlayType('audio/mpeg'), - 'opus' : X_Audio_rawAudio.canPlayType('audio/ogg; codecs="opus"'), - 'ogg' : X_Audio_rawAudio.canPlayType('audio/ogg; codecs="vorbis"'), - 'wav' : X_Audio_rawAudio.canPlayType('audio/wav; codecs="1"'), - 'aac' : X_Audio_rawAudio.canPlayType('audio/aac'), - 'm4a' : X_Audio_rawAudio.canPlayType('audio/x-m4a') + X_Audio_rawAudio.canPlayType('audio/m4a') + X_Audio_rawAudio.canPlayType('audio/aac'), - 'mp4' : X_Audio_rawAudio.canPlayType('audio/x-mp4') + X_Audio_rawAudio.canPlayType('audio/mp4') + X_Audio_rawAudio.canPlayType('audio/aac'), - 'weba' : X_Audio_rawAudio.canPlayType('audio/webm; codecs="vorbis"') + 'mp3' : X_TEMP.rawAudio.canPlayType('audio/mpeg'), + 'opus' : X_TEMP.rawAudio.canPlayType('audio/ogg; codecs="opus"'), + 'ogg' : X_TEMP.rawAudio.canPlayType('audio/ogg; codecs="vorbis"'), + 'wav' : X_TEMP.rawAudio.canPlayType('audio/wav; codecs="1"'), + 'aac' : X_TEMP.rawAudio.canPlayType('audio/aac'), + 'm4a' : X_TEMP.rawAudio.canPlayType('audio/x-m4a') + X_TEMP.rawAudio.canPlayType('audio/m4a') + X_TEMP.rawAudio.canPlayType('audio/aac'), + 'mp4' : X_TEMP.rawAudio.canPlayType('audio/x-mp4') + X_TEMP.rawAudio.canPlayType('audio/mp4') + X_TEMP.rawAudio.canPlayType('audio/aac'), + 'weba' : X_TEMP.rawAudio.canPlayType('audio/webm; codecs="vorbis"') }; (function( X_Audio_codecs, k, v ){ for( k in X_Audio_codecs ){ @@ -74,13 +106,13 @@ if( X_Audio_constructor && !X_Audio_HTMLAudioWrapper_badOperaAndroid ){ } else { // iOS3.2.3 X_Audio_codecs = { - 'mp3' : X_UA[ 'IE' ] || X_UA[ 'Chrome' ] || ( X_UA[ 'Windows' ] && X_UA[ 'Safari' ] ), - 'ogg' : 5 <= X_UA[ 'Gecko' ] || X_UA[ 'Chrome' ] || X_UA[ 'Opera' ] , - 'wav' : X_UA[ 'Gecko' ] || X_UA[ 'Opera' ] || ( X_UA[ 'Windows' ] && X_UA[ 'Safari' ] ), - 'aac' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], - 'm4a' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], - 'mp4' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], - 'weba' : 2 <= X_UA[ 'Gecko' ] || 10.6 <= X_UA[ 'Opera' ] // firefox4+(Gecko2+) + 'mp3' : X_UA[ 'IE' ] || X_UA[ 'Chrome' ] || ( X_UA[ 'Windows' ] && X_UA[ 'Safari' ] ), + 'ogg' : 5 <= X_UA[ 'Gecko' ] || X_UA[ 'Chrome' ] || X_UA[ 'Opera' ] , + 'wav' : X_UA[ 'Gecko' ] || X_UA[ 'Opera' ] || ( X_UA[ 'Windows' ] && X_UA[ 'Safari' ] ), + 'aac' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], + 'm4a' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], + 'mp4' : X_UA[ 'IE' ] || X_UA[ 'WebKit' ], + 'weba' : 2 <= X_UA[ 'Gecko' ] || 10.6 <= X_UA[ 'Opera' ] // firefox4+(Gecko2+) }; (function( X_Audio_codecs, k ){ for( k in X_Audio_codecs ){ @@ -95,79 +127,91 @@ if( X_Audio_constructor && !X_Audio_HTMLAudioWrapper_badOperaAndroid ){ })( X_Audio_codecs ); }; - X_Audio_HTMLAudioWrapper = X_Audio_AbstractAudioBackend[ 'inherits' ]( + X_HTMLAudio = X_Audio_AbstractAudioBackend[ 'inherits' ]( 'X.AV.HTML5AudioWrapper', X_Class.POOL_OBJECT, { - _playTime : 0, - _closed : true, - _loaded : false, - _beginTime : 0, - _playForDuration : 0, - _lastCurrentTime : 0, - _src : '', + _closed : true, + _loaded : false, + _ready : false, + _src : '', - isM4A : false, - shortPlayFix : 0, + _currentFixStart : 0, + _currentFixBegin : 0, + + _durationFixPhase : X_HTMLAudio_durationFix ? 1 : 0, + _durationFixSkip : X_HTMLAudio_durationFix && !X_HTMLAudio_need1stTouch, + _lastCurrentTime : 0, + + + _shortPlayFixON : false, + _shortPlayFixTime : 0, + + _endedFixON : false, 'Constructor' : function( target, source, option ){ var raw; this.target = target || this; this._closed = false; + this._src = source; - this.isM4A = X_URL_getEXT( source ) === 'm4a'; + if( X_HTMLAudio_shortPlayFix ){ + this._shortPlayFixON = X_URL_getEXT( source ) === 'm4a'; + }; this.setState( option ); if( option[ 'useVideo' ] ){ - this[ '_rawObject' ] = raw = document.createElement( 'video' ); - raw.preload = 'none'; // auto, metadata, none - //raw.autoplay = false, // no-auto - raw.loop = false; - raw.muted = false; - raw.crossorigin = option[ 'crossorigin' ] || ''; //crossorigin: "anonymous", X.URL.isSameDomain() で切り替え - raw.style.cssText = 'position:absolute;bottom:0;left:-50px;width:100px;height:100px;opacity:0;'; - raw.controls = false; + raw = document.createElement( 'video' ); + raw.preload = 'none'; // auto, metadata, none + raw.autoplay = false, // no-auto + raw.loop = false; + raw.muted = false; + raw.crossorigin = option[ 'crossorigin' ] || ''; //crossorigin: "anonymous", X.URL.isSameDomain() で切り替え + raw.style.cssText = 'position:absolute;bottom:0;left:-50px;width:100px;height:100px;opacity:0;'; + raw.controls = false; raw.WebKitPlaysInline = true; - raw.src = source; - //raw.onclick = "alert('play');this.actualPlay();"; + raw.src = source; document.body.appendChild( raw ); - //raw.load(); } else { - this[ '_rawObject' ] = X_Audio_rawAudio || new X_Audio_constructor( source ); + raw = X_TEMP.rawAudio || new X_Audio_constructor( source ); // X_Doc_create( 'audio', { src : source } )[ 'appendTo' ]( X.Doc.body ); - this[ '_rawObject' ].autobuffer = false; - this._src = source; + raw.autobuffer = raw.autoplay = false; }; + this[ '_rawObject' ] = raw; + this[ 'listen' ]( [ - 'loadstart', 'load', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', - 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', - 'ratechange', 'durationchange', 'volumechange' ], this.handleEventProxy ); - - //document.body.appendChild( this[ '_rawObject' ] ); - this[ '_rawObject' ].autoplay = false; + X_EVENT_KILL_INSTANCE, + X_HTMLAudio_playTrigger, + //'loadstart', 'load', + 'progress', 'error', + // 'suspend', 'abort', 'emptied', 'stalled', + // 'play', 'pause', 'seeked', 'ratechange', 'volumechange', + 'loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', + 'playing', 'waiting', 'seeking', + 'durationchange', 'timeupdate', 'ended' ] ); - if( X_Audio_rawAudio === this[ '_rawObject' ] ){ - if( X_Audio_HTMLAudioWrapper_badOperaAndroid ){ - X_Audio_HTMLAudioWrapper_badOperaAndroid && alert( 12 ); - X_EventDispatcher_toggleAllEvents( this, false ); - this[ '_rawObject' ] = new X_Audio_constructor( X_URL_toAbsolutePath( source ) ); - //X_EventDispatcher_toggleAllEvents( this, true ); - } else { - X_Audio_rawAudio.src = source; - }; - - //this[ '_rawObject' ] = new X_Audio_constructor( X_URL_toAbsolutePath( source ) ); - /*!X_Audio_Sprite_needTouchFirst && */ X_Audio_rawAudio.load(); // 要る? - X_Audio_rawAudio = null; + if( X_TEMP.rawAudio ){ + raw.src = source; + raw.load(); // 要る? + X_TEMP.rawAudio = null; }; - - this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE ); }, handleEvent : function( e ){ + var raw = this[ '_rawObject' ], + _ended = e.type === 'ended', + ended = _ended, + ready = e.type === X_HTMLAudio_playTrigger, + eventType, duration, end, now; + + // global に公開 + //window[ '__rawAudio' ] = this[ '_rawObject' ]; + + e.type !== 'timeupdate' && console.log( ' > ' + e.type ); + switch( e.type ){ case X_EVENT_KILL_INSTANCE : @@ -178,312 +222,290 @@ if( X_Audio_constructor && !X_Audio_HTMLAudioWrapper_badOperaAndroid ){ delete this._closed; delete this._loaded; - this[ '_rawObject' ].src = ''; - this[ '_rawObject' ].load(); + raw.src = ''; + raw.load(); // removeChild for video break; - }; - }, - /* - * http://uguisu.skr.jp/html/table3.html - */ - handleEventProxy : function( e ){ - var type, loaded, end, now; - - X_Audio_HTMLAudioWrapper_badOperaAndroid && alert( e.type ); - - // global に公開 - //window[ '__rawAudio' ] = this[ '_rawObject' ]; - - /* X_Audio_HTMLAudioWrapper_ieMobile9Fix && */ e.type !== 'timeupdate' && console.log( e.type ); - - switch( e.type ){ - case 'loadstart' : // ブラウザがコンテンツの検索を開始した場合に発生 - break; - case 'progress' : // ブラウザがコンテンツの取得を実行した場合に発生 + + //case 'loadstart' : // ブラウザがコンテンツの検索を開始した場合に発生 + //break; + case 'progress' : // ブラウザがコンテンツの取得を実行した場合に発生 console.log( e.loaded + ' ' + e.total * 100 + '%' ); - // iem9 で常に0 this[ '_rawObject' ].networkState; + // iem9 で常に0 raw.networkState; // opera Android 12 で buffered.end() へのアクセスはエラー try catch も無効、iem9 は常に end(0) = 0 - //console.log( 'buffered.end ' + this[ '_rawObject' ].buffered && this[ '_rawObject' ].buffered.end(0) ); + //console.log( 'buffered.end ' + raw.buffered && raw.buffered.end(0) ); break; - case 'canplay' : // 今すぐに再生を再開できるが、バッファリングが不十分でコンテンツを最後まで表示できないと予測している場合に発生 - if( X_Audio_HTMLAudioWrapper_durationFix && this._playForDuration === 0 && !X_UA[ 'AndroidChromeBrowser' ] ){ - console.log( '[duration fix]開始 - ' + this[ '_rawObject' ].duration ); - this._playForDuration = 1; - this[ '_rawObject' ].play(); - this[ '_rawObject' ].currentTime = this._beginTime / 1000; // 必要! - return; + case 'loadeddata' : // コンテンツの表示を現在の再生位置で初めて行えるようになった場合に発生 + if( !this._endedFixON ){ + ready = true; + }; + case 'canplay' : // 今すぐに再生を再開できるが、バッファリングが不十分でコンテンツを最後まで表示できないと予測している場合に発生 + if( X_HTMLAudio_durationFix && !X_HTMLAudio_need1stTouch && this._durationFixPhase === 1 ){ + console.log( '▲ DurationFix の開始 @' + e.type ); + this._durationFixPhase = 2; + raw.play(); + raw.currentTime = 0; // 必要! }; - case 'loadedmetadata' : // ブラウザがメディアリソースの長さと寸法を判定した場合に発生 - case 'loadeddata' : // コンテンツの表示を現在の再生位置で初めて行えるようになった場合に発生 case 'canplaythrough' : // 今すぐに再生を開始してもバッファリングで停止することなく最後まで表示できると予測している場合に発生 - X_Audio_HTMLAudioWrapper_durationFix && console.log( '[duration fix]' + e.type + ' ' + this._playForDuration ); - if( X_Audio_HTMLAudioWrapper_durationFix && this._playForDuration !== 2 ) return; - this.duration = this.duration || this[ '_rawObject' ].duration * 1000; - break; - - case 'stalled' : // ブラウザがコンテンツの取得を試みたが、データがまだ用意されていない場合に発生 - // Android2 で ready 扱い? - case 'suspend' : // ブラウザが意図的にコンテンツの取得を現在行っていない場合に発生(ダウンロードは未完了) - // iOS で ready 扱い - case 'emptied' : // 読み込み中に致命的なエラーが発生したか、実行状態ででload()メソッドが実行された場合に発生 - case 'abort' : // ダウンロードの完了前にコンテンツの取得を停止した場合に発生(この停止はエラーによるものではない) - break; - - case 'error' : // コンテンツの取得実行中にエラーが発生した場合に発生 - type = X_EVENT_ERROR; - break; - - case 'playing' : // 再生が開始された場合に発生 - if( X_Audio_HTMLAudioWrapper_currentTimeFix ){ - this._playTime = X_Timer_now(); + if( this._endedFixON ){ + this._endedFixON = false; + this.actualPlay(); + console.log( '▽ onEndedFix @' + e.type ); }; - type = X_EVENT_MEDIA_PLAYING; - case 'play' : // 再生が開始された。play()メソッドからの復帰後に発生する場合に発生 - case 'pause' : // 再生が一時停止された。pauseメソッドからの復帰後に発生する場合に発生 - case 'seeked' : // シークがfalseに変化した場合に発生 - case 'ratechange' : // defaultPlaybackRate属性とplaybackRate属性のどちらかが更新された場合に発生 - case 'volumechange' : // volume属性とmuted属性のどちらかが変化した場合に発生 - if( this._playForDuration === 1 ) return; - break; - - case 'waiting' : // 次のフレームが利用不可のため再生を停止したが、そのフレームがやがて利用可能になると想定している場合に発生 - type = X_EVENT_MEDIA_WAITING; - case 'seeking' : // シークがtrueに変化し、イベントを発生させるのに十分な時間がシーク操作にかかっている場合に発生 - type = type || X_EVENT_MEDIA_SEEKING; - if( this._playForDuration === 1 ) return; - break; - - case 'ended' : - if( !this._closed && this.autoLoop ){ - 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( X_Audio_HTMLAudioWrapper_needPlayOnended ); - }; - // Android4.1.1 ended 後に曲の再生が継続できない - return; + case 'loadedmetadata' : // ブラウザがメディアリソースの長さと寸法を判定した場合に発生 + case 'durationchange' : // duration属性が更新された場合に発生 + if( !this.duration ){ + duration = raw.duration; }; - type = X_EVENT_MEDIA_ENDED; - this.seekTime = 0; - delete this.playing; break; - // TODO firefox で 短い音声でtimeupdate, ended が発火しない - case 'timeupdate' : // 通常の再生が行われ現在の再生位置の変化が起こった場合に発生 - if( X_Audio_HTMLAudioWrapper_ieMobile9Fix ){ - if( this._playForDuration === 1 ){ - console.log( 'tu ' + this[ '_rawObject' ].duration ); - if( !this.duration && X_Type_isFinite( this[ '_rawObject' ].duration ) && 0 < this[ '_rawObject' ].duration ){ - this.duration = this.duration || this[ '_rawObject' ].duration * 1000; - this._playForDuration = 2; - loaded = true; - break; + // TODO firefox で 短い音声でtimeupdate, ended が発火しない <- 最後の音に無音部分を追加する + case 'timeupdate' : // 通常の再生が行われ現在の再生位置の変化が起こった場合に発生 + if( this._durationFixPhase & 3 ){ // 1 or 2 + duration = raw.duration; + } else + if( raw.currentTime === this._lastCurrentTime ){ + eventType = X_EVENT_MEDIA_WAITING; + } else { + this._lastCurrentTime = raw.currentTime; + + if( this.playing ){ + end = X_AudioWrapper_getEndTime( this ) + this._shortPlayFixTime; + now = this.getActualCurrentTime(); + //console.log( now + ' / ' + end ); + if( 0 + end <= 0 + now ){ // 0+ なぜか iem9 で必要,,, + if( this.autoLoop ){ + console.log( '☆★☆ 曲の最後に到達 @timeupdate' ); + ended = true; + if( X_HTMLAudio_endedFixIOS ) _ended = true; + } else { + this.actualPause(); + eventType = X_EVENT_MEDIA_ENDED; + }; } else { - this[ '_rawObject' ].currentTime = this._beginTime / 1000; // 必要! - return; + eventType = X_EVENT_MEDIA_PLAYING; }; - } else - if( this[ '_rawObject' ].currentTime === this._lastCurrentTime ){ - this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); - return; }; - this._lastCurrentTime = this[ '_rawObject' ].currentTime; }; - this.duration = this.duration || this[ '_rawObject' ].duration * 1000; - - if( this.playing ){ - end = X_AudioWrapper_getEndTime( this ) + this.shortPlayFix; - now = this.getActualCurrentTime(); - //console.log( now + ' / ' + end ); - if( 0 + end <= 0 + now ){ // 0+ なぜか iem9 で必要,,, - if( this.autoLoop ){ - 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(); - }; - } else { - this.actualPause(); - this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); - }; - return; - }; - } else { - return; - }; - type = X_EVENT_MEDIA_PLAYING; break; + + //case 'stalled' : // ブラウザがコンテンツの取得を試みたが、データがまだ用意されていない場合に発生 + // Android2 で ready 扱い? + //case 'suspend' : // ブラウザが意図的にコンテンツの取得を現在行っていない場合に発生(ダウンロードは未完了) + // iOS で ready 扱い + //case 'emptied' : // 読み込み中に致命的なエラーが発生したか、実行状態ででload()メソッドが実行された場合に発生 + //case 'abort' : // ダウンロードの完了前にコンテンツの取得を停止した場合に発生(この停止はエラーによるものではない) + // break; - case 'durationchange' : // duration属性が更新された場合に発生 + case 'error' : // コンテンツの取得実行中にエラーが発生した場合に発生 + // Opera12 src = '' で error が発生、無視する + // eventType = X_EVENT_ERROR; + break; - if( !X_Audio_HTMLAudioWrapper_durationFix ){ - this.duration = this[ '_rawObject' ].duration * 1000; - console.log( 'duration : ' + this.duration ); - } else - // Desktop Opera では Infinity, IEM9 では NaN, Android標準ブラウザ(Chrome)では 0 - if( !this.duration && X_Type_isFinite( this[ '_rawObject' ].duration ) && 0 < this[ '_rawObject' ].duration ){ - - //console.log( this[ '_rawObject' ].duration ); - - this.duration = this[ '_rawObject' ].duration * 1000; - - if( this._playForDuration === 0 ) this._playForDuration = 2; - - if( this._playForDuration === 1 ){ - this._playForDuration = 2; - - console.log( '[duration fix] Loaded ' + this._loaded ); - - if( this._loaded ){ - this[ '_rawObject' ].currentTime = this._beginTime / 1000; - console.log( '[duration fix] 設定 ' + this._beginTime ); - return; - }; - - loaded = true; - console.log( '[duration fix] 完了' + this.duration ); - - if( this.autoplay ){ - this[ '_rawObject' ].currentTime = this._beginTime / 1000; - } else - if( X_UA[ 'Opera' ] ){ - // Opera12.17 WinXP で勝手に再生される不具合 - // これで一応再生は止まる、、、 - this[ '_rawObject' ].src = ''; - //this[ '_rawObject' ].load(); - }; - }; - + case 'playing' : // 再生が開始された場合に発生 + if( X_HTMLAudio_volumeFix ){ + raw.volume = this.gain; }; + if( X_HTMLAudio_currentTimeFix ){ + this._currentFixStart = X_Timer_now(); // 正確な再生開始時間に補正 + }; + eventType = !this._durationFixSkip && !this._endedFixON ? X_EVENT_MEDIA_PLAYING : X_EVENT_MEDIA_WAITING; + //case 'play' : // 再生が開始された。play()メソッドからの復帰後に発生する場合に発生 + //case 'pause' : // 再生が一時停止された。pauseメソッドからの復帰後に発生する場合に発生 + //case 'seeked' : + //case 'ratechange' : // defaultPlaybackRate属性とplaybackRate属性のどちらかが更新された場合に発生 + //case 'volumechange' : // volume属性とmuted属性のどちらかが変化した場合に発生 break; + case 'waiting' : // 次のフレームが利用不可のため再生を停止したが、そのフレームがやがて利用可能になると想定している場合に発生 + eventType = X_EVENT_MEDIA_WAITING; + break; + case 'seeking' : // シークがtrueに変化し、イベントを発生させるのに十分な時間がシーク操作にかかっている場合に発生 + eventType = X_EVENT_MEDIA_SEEKING; + break; }; - - if( !this._loaded && ( loaded || e.type === X_Audio_HTMLAudio_playTrigger || e.type === 'loadeddata' ) ){ + // duration は Infinity, NaN, 0 の場合があるため、これを除外する + if( 0 < duration && X_Type_isFinite( duration ) ){ + this.duration = duration * 1000; + + if( this._durationFixPhase === 2 ){ + console.log( '▼ DurationFix の終了 @' + e.type ); + this._durationFixPhase = 4; + + ready = true; + + if( this.autoplay || this._loaded ){ + console.log( '☆ 再生 <- DurationFix の終了' ); + this._durationFixSkip = false; + this.actualPlay(); + } else + if( X_HTMLAudio_pauseFix ){ + console.log( '☆ PAUSE <- DurationFix の終了' ); + //raw.src = ''; + //raw.load(); + this.actualPause(); + }; + } else + if( this._durationFixPhase ){ + this._durationFixPhase = 4; + }; + }; + + this._loaded = this._loaded || ready; + + // + if( ended ){ + if( !this._closed && this.autoLoop ){ + if( !( this.target[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){ + this.looped = true; + this.target[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED ); + ( X_HTMLAudio_endedFixAOSP3 || X_HTMLAudio_endedFixAOSP4 || X_HTMLAudio_endedFixIOS ) && _ended && console.log( '☆★☆ 音声の継続用の play() @ended' ); + this.actualPlay( ( X_HTMLAudio_endedFixAOSP4 || X_HTMLAudio_endedFixIOS ) && _ended, ( X_HTMLAudio_endedFixAOSP3 || X_HTMLAudio_endedFixAOSP2 ) && _ended ); + }; + // Android4.1.1 ended 後に曲の再生が継続できない + } else { + this.seekTime = 0; + delete this.playing; + this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); + }; + } else + if( this._loaded && this.duration && !this._ready ){ + this._ready = true; this.autoplay && X_Timer_once( 16, this, this.play ); - this._loaded = true; this.target[ 'asyncDispatch' ]( X_EVENT_READY ); console.log( '> Audio Loaded!! ' + e.type + ' d:' + ( this.duration | 0 ) ); - return; - }; - - if( !loaded && type ){ - // console.log( '(2) ' + e.type + ' d:' + ( this.duration | 0 ) ); - this.target[ 'dispatch' ]( type ); - type === X_EVENT_ERROR && this[ 'kill' ](); + } else + if( eventType ){ + this.target[ 'dispatch' ]( eventType ); + eventType === X_EVENT_ERROR && this[ 'kill' ](); }; }, - actualPlay : function( forcePlay ){ - var begin, end; + actualPlay : function( forcePlay, forceReload ){ + var raw = this[ '_rawObject' ], + begin, end; // もし kill 後に autoplayTimer で呼ばれても、_closed==true なので平気 if( this._closed ) return; - if( !this._loaded && !X_Audio_HTMLAudioWrapper_ieMobile9Fix /* && !X_Audio_Sprite_inTouchAction */ ){ - this.autoplay = true; - return; - }; - if( X_Audio_HTMLAudioWrapper_ieMobile9Fix && this._playForDuration === 0 ){ - console.log( 'DurationFix開始 - ' + this[ '_rawObject' ].duration ); - this._playForDuration = 1; + + if( !raw.src ){ // X_HTMLAudio_pauseFix によって src が空になっている + console.log( '○ 削除された audio.src の復帰' ); + raw.src = this._src; + //return; + }; + + if( !this._ready && ( !X_HTMLAudio_durationFix || !X_HTMLAudio_need1stTouch ) ){ + this.autoplay = true; + return; + }; + + if( X_HTMLAudio_durationFix && X_HTMLAudio_need1stTouch && this._durationFixPhase === 1 ){ + console.log( '▲ DurationFix の開始(タッチ用)' ); + this._durationFixPhase = 2; }; end = X_AudioWrapper_getEndTime( this ); - begin = this._beginTime = X_AudioWrapper_getStartTime( this, end, true ); + begin = X_AudioWrapper_getStartTime( this, end, true ); - if( X_Audio_HTMLAudioWrapper_shortPlayFix && this.isM4A ){ - this.shortPlayFix = ( 1000 < end - begin ) ? 200 : 400; - if( this.duration < end + this.shortPlayFix ){ - this.shortPlayFix = this.duration - end; - }; - }; + this._lastCurrentTime = begin / 1000; - if( !this[ '_rawObject' ].src ){ - this._beginTime = begin; - this[ '_rawObject' ].src = this._src; - delete this._playForDuration; + if( this._shortPlayFixON ){ + this._shortPlayFixTime = ( 1000 < end - begin ) ? 200 : 400; + if( this.duration < end + this._shortPlayFixTime ){ + this._shortPlayFixTime = this.duration - end; + }; }; - if( !this.playing || forcePlay ){ - if( X_UA[ 'Chrome' ] ){ // [CHROME][FIX] volume TODO どの version で 修正される? - // [!] delay - X_Timer_once( 0, this, this._fixForChrome ); - this[ '_rawObject' ].volume = 0; - } else { - this[ '_rawObject' ].volume = X_Audio_HTMLAudioWrapper_ieMobile9Fix ? 1 : this.gain; - }; - this[ '_rawObject' ].play(); - this.playing = true; - } else - if( X_UA[ 'Gecko' ] ){ - // Gecko PC + Android でseek時に再生がしばしば止まる問題の修正 - this[ '_rawObject' ].play(); - }; - - //http://himaxoff.blog111.fc2.com/blog-entry-97.html - //Firefox3.6では一度も play() していない状態で currentTime = 0 を実行するとエラーになる。 - //また、GoogleChrome7 では currentTime = 0 直後に play() すると、pause()した位置前後の音が混ざることがある。(少なくとも自分の環境では) - this[ '_rawObject' ].currentTime = this._lastCurrentTime = begin / 1000 | 0; - - console.log( '[HTMLAudio] play ' + begin + ' -> ' + end ); - - if( X_Audio_HTMLAudioWrapper_currentTimeFix ){ - this._beginTime = begin; - this._playTime = X_Timer_now(); - }; + if( this._durationFixSkip || this._endedFixON ){ + console.log( '☆ audio.play をスキップ ' + begin + ' -> ' + end + ' crt:' + ( raw.currentTime | 0 ) ); + } else { + if( !this.playing ){ + if( X_HTMLAudio_volumeFix ){ + raw.volume = 0; + } else { + raw.volume = X_HTMLAudio_volumeEnabled ? this.gain : 1; + }; + raw.play(); + this.playing = true; + } else + if( X_HTMLAudio_needPlayForSeek || forcePlay ){ + raw.play(); + console.log( '[HTMLAudio] currentTime より先.' ); + }; + + //http://himaxoff.blog111.fc2.com/blog-entry-97.html + //Firefox3.6では一度も play() していない状態で currentTime = 0 を実行するとエラーになる。 + //また、GoogleChrome7 では currentTime = 0 直後に play() すると、pause()した位置前後の音が混ざることがある。(少なくとも自分の環境では) + raw.currentTime = this._lastCurrentTime; + console.log( '[HTMLAudio] play ' + begin + ' -> ' + end + ' crt:' + ( raw.currentTime | 0 ) + ' last:' + this._lastCurrentTime ); + + // Android4.0.5 で ended イベント時に currentTime が duration に張り付いたまま変更できない + if( forceReload || ( raw.duration && raw.currentTime === raw.duration ) ){ + console.log( '△ onEndedFix の開始' ); + raw.src = ''; + raw.src = this._src; + raw.currentTime = this._lastCurrentTime; + this.playing = false; + this._endedFixON = true; + this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); + X_HTMLAudio_endedFixAOSP2 && raw.load(); + }; + }; + /* if( X_HTMLAudio_durationFix ){ + this._currentFixBegin = begin; + } else */ + if( X_HTMLAudio_currentTimeFix ){ + this._currentFixBegin = begin; + this._currentFixStart = X_Timer_now(); + }; }, - - // [CHROME][FIX] volume - _fixForChrome : X_UA[ 'Chrome' ] && function(){ - !this._closed && ( this[ '_rawObject' ].volume = this.gain ); - }, actualPause : function(){ - if( !this.playing ) return; - console.log( '[HTMLAudio] pause' ); this.seekTime = this.getActualCurrentTime(); - delete this._playTime; + delete this._currentFixStart; - !this[ '_rawObject' ].error && this[ '_rawObject' ].pause(); - - if( X_Audio_HTMLAudioWrapper_durationFix && X_UA[ 'Opera' ] ){ - this[ '_rawObject' ].src = ''; - // load(); - }; - delete this.playing; + !this[ '_rawObject' ].error && this[ '_rawObject' ].pause(); + + if( X_HTMLAudio_pauseFix ){ + this[ '_rawObject' ].src = ''; + if( X_HTMLAudio_durationFix ){ + delete this._durationFixPhase; + delete this._durationFixSkip; + }; + }; + delete this.playing; }, getActualCurrentTime : function(){ - return ( X_Audio_HTMLAudioWrapper_currentTimeFix ? - X_Timer_now() - this._playTime + this._beginTime : - this[ '_rawObject' ].currentTime * 1000 | 0 ); + return ( X_HTMLAudio_currentTimeFix ? + X_Timer_now() - this._currentFixStart + this._currentFixBegin : + this[ '_rawObject' ].currentTime * 1000 | 0 ); }, /* http://www.w3schools.com/tags/av_prop_error.asp 1 = MEDIA_ERR_ABORTED - fetching process aborted by user - 2 = MEDIA_ERR_NETWORK - error occurred when downloading - 3 = MEDIA_ERR_DECODE - error occurred when decoding - 4 = MEDIA_ERR_SRC_NOT_SUPPORTED - audio/video not supported - */ + 2 = MEDIA_ERR_NETWORK - error occurred when downloading + 3 = MEDIA_ERR_DECODE - error occurred when decoding + 4 = MEDIA_ERR_SRC_NOT_SUPPORTED - audio/video not supported + */ getActualError : function(){ return this[ '_rawObject' ].error || 0; }, afterUpdateState : function( result ){ if( result & 3 ){ // seek - this.actualPlay(); + this.actualPlay(); } else - if( result & 4 ){ - this[ '_rawObject' ].volume = X_Audio_HTMLAudioWrapper_ieMobile9Fix ? 1 : this.gain; + if( ( result & 4 ) && X_HTMLAudio_volumeEnabled ){ + this[ '_rawObject' ].volume = this.gain; }; } @@ -527,23 +549,23 @@ if( X_Audio_constructor && !X_Audio_HTMLAudioWrapper_badOperaAndroid ){ proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : X_Audio_codecs[ ext ] } ); }, - klass : X_Audio_HTMLAudioWrapper + klass : X_HTMLAudio } ); /* * * howler.js - * codecs = { - mp3: !!audioTest.canPlayType('audio/mpeg;').replace(/^no$/, ''), - opus: !!audioTest.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ''), - ogg: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''), - wav: !!audioTest.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''), - aac: !!audioTest.canPlayType('audio/aac;').replace(/^no$/, ''), - m4a: !!(audioTest.canPlayType('audio/x-m4a;') || audioTest.canPlayType('audio/m4a;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''), - mp4: !!(audioTest.canPlayType('audio/x-mp4;') || audioTest.canPlayType('audio/mp4;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''), - weba: !!audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '') - }; + * codecs = { + mp3: !!audioTest.canPlayType('audio/mpeg;').replace(/^no$/, ''), + opus: !!audioTest.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ''), + ogg: !!audioTest.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''), + wav: !!audioTest.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''), + aac: !!audioTest.canPlayType('audio/aac;').replace(/^no$/, ''), + m4a: !!(audioTest.canPlayType('audio/x-m4a;') || audioTest.canPlayType('audio/m4a;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''), + mp4: !!(audioTest.canPlayType('audio/x-mp4;') || audioTest.canPlayType('audio/mp4;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''), + weba: !!audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '') + }; */ }; diff --git a/0.6.x/js/07_audio/03_XSilverlightAudio.js b/0.6.x/js/07_audio/03_XSilverlightAudio.js index 6999b81..30d9548 100644 --- a/0.6.x/js/07_audio/03_XSilverlightAudio.js +++ b/0.6.x/js/07_audio/03_XSilverlightAudio.js @@ -15,7 +15,7 @@ var X_Audio_SLAudioWrapper, X_Audio_SLAudio_uid = 0; -if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ +if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] && !X_HTMLAudio ){ X_TEMP.slaudioInit = function(){ // @@ -342,7 +342,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ // SilverlightAudio.pause actualPause : function(){ - if( this.error || !this.playing ) return; + if( this.error /* || !this.playing */ ) return; this._lastUserAction = 'pause'; this.seekTime = this.getActualCurrentTime(); @@ -390,9 +390,10 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ } ); + /* function slerror(){ alert( 'slerror' ); - }; + }; */ X_Audio_BACKENDS.push( { backendName : 'Silverlight Audio', @@ -404,8 +405,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ }, detect : function( proxy, source, ext ){ - var ok = ext === 'mp3' || ext === 'wma' || ext === 'wav'; - proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ok } ); + proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'wma' || ext === 'wav' } ); }, klass : X_Audio_SLAudioWrapper diff --git a/0.6.x/js/07_audio/10_XAudioSprite.js b/0.6.x/js/07_audio/10_XAudioSprite.js index 0aa4206..99ff9b2 100644 --- a/0.6.x/js/07_audio/10_XAudioSprite.js +++ b/0.6.x/js/07_audio/10_XAudioSprite.js @@ -232,6 +232,7 @@ X_Audio_Sprite_members = { 'loopEndTime' : X_Audio_Sprite_lengthSilence }); } else { + track.play( preset[ 0 ], preset[ 1 ], true, 0, X_Audio_Sprite_lengthSilence ); }; }; @@ -357,7 +358,7 @@ function X_AudioSprite_backendHandler( e ){ last[ 'listenOnce' ]( X_EVENT_READY, this, X_AudioSprite_backendHandler ); // READY, needTouchForPlay, needTouchForLoad - if( X_Audio_HTMLAudioWrapper_durationFix && !X_Audio_Sprite_needTouchFirst ){ + if( X_HTMLAudio_durationFix && !X_Audio_Sprite_needTouchFirst ){ for( i = 0; i < X_Audio_Sprite_TEMP.tracks.length; ++i ){ this[ 'pause' ]( i ); }; @@ -405,7 +406,7 @@ function X_Audio_Sprite_handleEvent( e ){ this[ 'asyncDispatch' ]( X_EVENT_MEDIA_ENDED ); // TODO uid }; - console.log( '[AudioSprite] ' + X_Audio_Sprite_TEMP.bgmPlaying + ' ' + !X_Audio_Sprite_TEMP.bgmTrack ); + //console.log( '[AudioSprite] bgmPlaying:' + X_Audio_Sprite_TEMP.bgmPlaying + ' ' + !X_Audio_Sprite_TEMP.bgmTrack ); // single track | iOS if( X_Audio_Sprite_TEMP.bgmPlaying && !X_Audio_Sprite_TEMP.bgmTrack ){