X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F07_audio%2F03_XSilverlightAudio.js;h=d6b41e49770ebdf0c234e3959132ba1d3486a954;hb=512e08f4d38eab417f9651277e8a50c08535cb07;hp=501326d33fb9266ec6d844c98444f229826788b8;hpb=20c3a948b20e52efc28fd103fc075d787c6d65d2;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/07_audio/03_XSilverlightAudio.js b/0.6.x/js/07_audio/03_XSilverlightAudio.js index 501326d..d6b41e4 100644 --- a/0.6.x/js/07_audio/03_XSilverlightAudio.js +++ b/0.6.x/js/07_audio/03_XSilverlightAudio.js @@ -12,25 +12,33 @@ * SilverlLight5 ie6&7(ietester,winxp), ie8(winxp) で動作確認。firefox32 では動作しない。(4以下の方がよい?) */ -var X_Audio_SLAudioWrapper, - X_Audio_SLAudio_uid = 0; +var X_SLAudio, + X_SLAudio_uid = 0; -if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ +if( X_Plugin_SILVER_LIGHT_VERSION ){ X_TEMP.slaudioInit = function(){ // // http://blog.yuhiisk.com/archive/2014/12/20/dynamic-loading-and-complete-processing-of-script.html - var s = document.createElement( '' ); + var s; - document.getElementsByTagName( 'head' )[ 0 ].appendChild( s ); + if( X_UA[ 'IE' ] < 9 ){ + s = document.createElement( '' ); + } else { + s = document.createElement( 'script' ); + s.id = 'silverlightaudio'; + s.type = 'text/xaml'; + }; + + X_elmHead.appendChild( s ); s.text = ''; delete X_TEMP.slaudioInit; }; // X.Node.inherits はできない。_rawObject は でなく silverlight - X_Audio_SLAudioWrapper = X_Audio_AbstractAudioBackend[ 'inherits' ]( - 'X.AV.SilverlightAudio', + X_SLAudio = X_AudioBase[ 'inherits' ]( + 'X.SilverlightAudio', X_Class.POOL_OBJECT, { '_rawType' : X_EventDispatcher_EVENT_TARGET_SILVER_LIGHT, @@ -45,21 +53,21 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ _lastState : '', _interval : 0, // setInterval timer id - Constructor : function( target, source, option ){ - !X_Audio_SLAudio_uid && X_TEMP.slaudioInit(); + 'Constructor' : function( disatcher, source, option ){ + !X_SLAudio_uid && X_TEMP.slaudioInit(); /* * [Silverlight 2]JavaScriptコードからSilverlightのオブジェクトを利用するには?[C#、VB] * http://www.atmarkit.co.jp/fdotnet/dotnettips/902slobjcallfromjs/slobjcallfromjs.html * このページのサンプルは sl5+firefox32 環境で動いている。xaml を js から利用する形ではなく、.xap を sl4 以下で作るのがよさそう. */ - - // TODO embed - this.target = target || this; + this.disatcher = disatcher || this; this._source = source; // X.Audio._slOnload_ は不可 - this._onload = 'XAudioSilverlightOnLoad' + ( ++X_Audio_SLAudio_uid ); - this._callback = window[ this._onload ] = X_Callback_create( this, this.onSLReady ); + this._onload = 'XAudioSilverlightOnLoad' + ( ++X_SLAudio_uid ); + this._callback = window[ this._onload ] = X_Closure_create( this, this.onSLReady ); + + // TODO embed this.xnodeObject = X_Node_body [ 'create' ]( 'object', { type : 'application/x-silverlight-2', @@ -86,7 +94,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ window[ this._onload ] = null; delete this._onload; - X_Callback_correct( this._callback ); + X_Closure_correct( this._callback ); delete this._callback; sender[ 'children' ][ 'add' ]( @@ -114,7 +122,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ if( this.playing ){ //X_Timer_once( 16, this, this.actualPlay ); } else { - this.target[ 'dispatch' ]( X_EVENT_ERROR ); // open failed + this.disatcher[ 'dispatch' ]( X_EVENT_ERROR ); // open failed this[ 'kill' ](); }; break; @@ -122,9 +130,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ case 'MediaOpened' : // http://msdn.microsoft.com/ja-jp/library/bb979710(VS.95).aspx this.duration = this[ '_rawObject' ][ 'NaturalDuration' ][ 'Seconds' ] * 1000; - this.target[ 'asyncDispatch' ]( X_EVENT_READY ); - - this.autoplay && X_Timer_once( 16, this, this.actualPlay ); + this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY ); break; case 'MediaEnded' : @@ -151,10 +157,10 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ case 'Opening' : switch( this._lastUserAction ){ case 'play' : - this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); break; case 'seek' : - this.target[ 'dispatch' ]( X_EVENT_MEDIA_SEEKING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_SEEKING ); break; case 'pause' : break; @@ -171,7 +177,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ this.playing = false; this._ended = true; this._paused = false; - this.target[ 'dispatch' ]( X_EVENT_ERROR ); + this.disatcher[ 'dispatch' ]( X_EVENT_ERROR ); this[ 'kill' ](); break; @@ -187,9 +193,9 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ case 'play': // play() -> file end -> event('ended') case 'seek': //this.seekTime = 0; - this._ended = true; - this._paused = false; - //this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); + this._ended = true; + this._paused = false; + //this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); //this.setCurrentTime( this.startTime ); break; case 'pause': @@ -208,31 +214,30 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ //this.playing = true; this._ended = false; this._paused = false; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); break; // stop() case 'Stopped': this.playing && X_Timer_once( 16, this, this.actualPlay ); - return; //this.playing = false; - this._ended = true; - this._paused = false; + //this._ended = true; + //this._paused = false; //this.setCurrentTime( this.startTime ); break; }; break; case X_EVENT_KILL_INSTANCE : - this.playing && this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); + this.playing && this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); this.playing && this.actualPause(); if( this._onload ){ // window への delete に ie5 は対応しないが、そもそも ie5 は Silverlight に非対応 window[ this._onload ] = null; delete this._onload; - X_Callback_correct( this._callback ); + X_Closure_correct( this._callback ); }; this.xnodeObject[ 'kill' ](); break; @@ -246,14 +251,14 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ // もし kill 後に autoplayTimer で呼ばれても、_closed==true なので平気 if( this.error ) return; if( !this.duration ){ - this.autoplay = true; + this._playReserved = true; return; }; this._lastUserAction = 0 <= this.seekTime ? 'seek' : 'play'; - end = X_AudioWrapper_getEndTime( this ); - begin = X_AudioWrapper_getStartTime( this, end, true ) | 0; + end = X_Audio_getEndTime( this ); + begin = X_Audio_getStartTime( this, end, true ) | 0; // 1 秒以下は指定できないため四捨五入 begin = ( begin / 1000 | 0 ) * 1000 + ( 500 < begin % 1000 ? 1000 : 0 ); @@ -290,9 +295,9 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ _onInterval : function(){ if( !this.playing ){ delete this._interval; - return X_Callback_UN_LISTEN; + return X_CALLBACK_UN_LISTEN; }; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); }, _onEnded : function(){ @@ -300,7 +305,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ delete this._timerID; if( this.playing ){ - //console.log( '> end ' + X_AudioWrapper_getEndTime( this ) + ' current:' + ( this.getActualCurrentTime() ) ); + //console.log( '> end ' + X_Audio_getEndTime( this ) + ' current:' + ( this.getActualCurrentTime() ) ); time = this.getActualCurrentTime(); if( time < this._beginTime ){ @@ -310,13 +315,13 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ console.log( ' > ' + time ); this._ended && this[ '_rawObject' ].play(); this._ended = false; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); - this._timerID = X_Timer_once( X_AudioWrapper_getEndTime( this ) - time, this, this._onEnded ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); + this._timerID = X_Timer_once( X_Audio_getEndTime( this ) - time, this, this._onEnded ); return; }; - time -= X_AudioWrapper_getEndTime( this ); - if( time < 0 ){ + time -= X_Audio_getEndTime( this ); + if( time < -50 ){ console.log( ' > まだ終わらない ' + time ); this._ended && this[ '_rawObject' ].play(); this._ended = false; @@ -326,32 +331,30 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ if( this.autoLoop ){ console.log( '========= loop?' ); - if( !( this.target[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_Callback_PREVENT_DEFAULT ) ){ + if( !( this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){ console.log( '========== loopした' ); this.looped = true; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED ); this.actualPlay(); }; } else { console.log( '========= pause' ); this.actualPause(); - this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED ); }; }; }, // SilverlightAudio.pause actualPause : function(){ - if( this.error || !this.playing ) return; + if( this.error ) return; this._lastUserAction = 'pause'; - this.seekTime = this.getActualCurrentTime(); this.playing = false; this._paused = true; this._ended = false; this[ '_rawObject' ].pause(); - //this.target[ 'dispatch' ]( 'pause' ); }, getActualCurrentTime : function(){ @@ -359,11 +362,13 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ }, afterUpdateState : function( result ){ + var end, halfway; + if( result & 3 ){ // seek this.actualPlay(); } else if( result & 1 ){ - end = X_AudioWrapper_getEndTime( this ); + end = X_Audio_getEndTime( this ); halfway = end < this.duration; this._timerID && X_Timer_remove( this._timerID ); @@ -390,25 +395,30 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){ } ); + /* function slerror(){ alert( 'slerror' ); - }; + }; */ X_Audio_BACKENDS.push( { - backendName : 'Silverlight Audio', + backendID : 8, + + backendName : 'Silverlight', canPlay : { 'mp3' : true, + 'm4a' : true, 'wma' : true, 'wav' : true }, detect : function( proxy, source, ext ){ - var ok = ext === 'mp3' || ext === 'wma' || ext === 'wav'; - proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ok } ); + // TODO source = .mp3#CBR + // 得意度で返す + proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'm4a' || ext === 'wma' || ext === 'wav' } ); }, - klass : X_Audio_SLAudioWrapper + klass : X_SLAudio } );