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=3a3f0b049bffc291db2e3189dc87d91251846d6f;hpb=1ed2190f012cf923f7e48d3c0d122aa56c56c5f3;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 3a3f0b0..d6b41e4 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_SLAudio, X_SLAudio_uid = 0; -if( X[ 'Pulgin' ][ 'Silverlight' ] ){ +if( X_Plugin_SILVER_LIGHT_VERSION ){ X_TEMP.slaudioInit = function(){ // @@ -30,7 +30,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ s.type = 'text/xaml'; }; - document.getElementsByTagName( 'head' )[ 0 ].appendChild( s ); + X_elmHead.appendChild( s ); s.text = ''; delete X_TEMP.slaudioInit; @@ -53,7 +53,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ _lastState : '', _interval : 0, // setInterval timer id - 'Constructor' : function( target, source, option ){ + 'Constructor' : function( disatcher, source, option ){ !X_SLAudio_uid && X_TEMP.slaudioInit(); /* @@ -61,7 +61,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ * http://www.atmarkit.co.jp/fdotnet/dotnettips/902slobjcallfromjs/slobjcallfromjs.html * このページのサンプルは sl5+firefox32 環境で動いている。xaml を js から利用する形ではなく、.xap を sl4 以下で作るのがよさそう. */ - this.target = target || this; + this.disatcher = disatcher || this; this._source = source; // X.Audio._slOnload_ は不可 this._onload = 'XAudioSilverlightOnLoad' + ( ++X_SLAudio_uid ); @@ -122,7 +122,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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; @@ -130,9 +130,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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' : @@ -159,10 +157,10 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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; @@ -179,7 +177,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ this.playing = false; this._ended = true; this._paused = false; - this.target[ 'dispatch' ]( X_EVENT_ERROR ); + this.disatcher[ 'dispatch' ]( X_EVENT_ERROR ); this[ 'kill' ](); break; @@ -195,9 +193,9 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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': @@ -216,7 +214,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ //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() @@ -232,7 +230,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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 ){ @@ -253,7 +251,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ // もし kill 後に autoplayTimer で呼ばれても、_closed==true なので平気 if( this.error ) return; if( !this.duration ){ - this.autoplay = true; + this._playReserved = true; return; }; @@ -299,7 +297,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ delete this._interval; return X_CALLBACK_UN_LISTEN; }; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING ); }, _onEnded : function(){ @@ -317,13 +315,13 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ console.log( ' > ' + time ); this._ended && this[ '_rawObject' ].play(); this._ended = false; - this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); + this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING ); this._timerID = X_Timer_once( X_Audio_getEndTime( this ) - time, this, this._onEnded ); return; }; time -= X_Audio_getEndTime( this ); - if( time < 0 ){ + if( time < -50 ){ console.log( ' > まだ終わらない ' + time ); this._ended && this[ '_rawObject' ].play(); this._ended = false; @@ -333,32 +331,30 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ 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(){ @@ -366,6 +362,8 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ }, afterUpdateState : function( result ){ + var end, halfway; + if( result & 3 ){ // seek this.actualPlay(); } else @@ -409,12 +407,15 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){ canPlay : { 'mp3' : true, + 'm4a' : true, 'wma' : true, 'wav' : true }, detect : function( proxy, source, ext ){ - proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'wma' || ext === 'wav' } ); + // TODO source = .mp3#CBR + // 得意度で返す + proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'm4a' || ext === 'wma' || ext === 'wav' } ); }, klass : X_SLAudio