OSDN Git Service

Version 0.6.187, add Scroll-Indicator for X.UI.ScrollBox, bugfix of X.HTMLAudio.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 03_XSilverlightAudio.js
index 7133272..3b9d94d 100644 (file)
@@ -15,7 +15,7 @@
 var X_SLAudio,\r
        X_SLAudio_uid = 0;\r
 \r
-if( X[ 'Pulgin' ][ 'Silverlight' ] ){\r
+if( X_Pulgin_SILVER_LIGHT_VERSION ){\r
        \r
        X_TEMP.slaudioInit = function(){\r
                //\r
@@ -30,7 +30,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                        s.type = 'text/xaml';\r
                };\r
                \r
-               document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );\r
+               X_elmHead.appendChild( s );\r
                s.text = '<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></Canvas>';\r
                \r
                delete X_TEMP.slaudioInit;\r
@@ -53,7 +53,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                        _lastState      : '',\r
                        _interval       : 0, // setInterval timer id\r
                        \r
-                       'Constructor' : function( target, source, option ){\r
+                       'Constructor' : function( disatcher, source, option ){\r
                                !X_SLAudio_uid && X_TEMP.slaudioInit();\r
                                \r
                                /*\r
@@ -61,7 +61,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                 * http://www.atmarkit.co.jp/fdotnet/dotnettips/902slobjcallfromjs/slobjcallfromjs.html\r
                                 * このページのサンプルは sl5+firefox32 環境で動いている。xaml を js から利用する形ではなく、.xap を sl4 以下で作るのがよさそう.\r
                                 */\r
-                               this.target      = target || this;\r
+                               this.disatcher   = disatcher || this;\r
                                this._source     = source;\r
                                // X.Audio._slOnload_ は不可\r
                        this._onload     = 'XAudioSilverlightOnLoad' + ( ++X_SLAudio_uid );\r
@@ -122,7 +122,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                if( this.playing ){\r
                                                        //X_Timer_once( 16, this, this.actualPlay );\r
                                                } else {\r
-                                                       this.target[ 'dispatch' ]( X_EVENT_ERROR ); // open failed\r
+                                                       this.disatcher[ 'dispatch' ]( X_EVENT_ERROR ); // open failed\r
                                                        this[ 'kill' ]();                                                       \r
                                                };\r
                                                break;\r
@@ -130,9 +130,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                        case 'MediaOpened' :\r
                                                // http://msdn.microsoft.com/ja-jp/library/bb979710(VS.95).aspx\r
                                                this.duration = this[ '_rawObject' ][ 'NaturalDuration' ][ 'Seconds' ] * 1000;\r
-                               this.target[ 'asyncDispatch' ]( X_EVENT_READY );\r
-                               \r
-                               this.autoplay && X_Timer_once( 16, this, this.actualPlay );\r
+                               this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY );\r
                                                break;\r
 \r
                                        case 'MediaEnded' :\r
@@ -159,10 +157,10 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                        case 'Opening' :\r
                                                                switch( this._lastUserAction ){\r
                                                                        case 'play' :\r
-                                                                               this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );\r
+                                                                               this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );\r
                                                                                break;\r
                                                                        case 'seek' :\r
-                                                                               this.target[ 'dispatch' ]( X_EVENT_MEDIA_SEEKING );\r
+                                                                               this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_SEEKING );\r
                                                                                break;\r
                                                                        case 'pause' :\r
                                                                                break;\r
@@ -179,7 +177,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                                this.playing = false;\r
                                                                this._ended  = true;\r
                                                                this._paused = false;\r
-                                                               this.target[ 'dispatch' ]( X_EVENT_ERROR );\r
+                                                               this.disatcher[ 'dispatch' ]( X_EVENT_ERROR );\r
                                                                this[ 'kill' ]();\r
                                                                break;\r
 \r
@@ -195,9 +193,9 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                                        case 'play': // play() -> file end -> event('ended')\r
                                                                        case 'seek':\r
                                                                                //this.seekTime = 0;\r
-                                                                               this._ended   = true;\r
-                                                                               this._paused  = false;\r
-                                                                               //this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
+                                                                               this._ended  = true;\r
+                                                                               this._paused = false;\r
+                                                                               //this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
                                                                                //this.setCurrentTime( this.startTime );\r
                                                                                break;\r
                                                                        case 'pause':\r
@@ -216,24 +214,23 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                                //this.playing = true;\r
                                                                this._ended  = false;\r
                                                                this._paused = false;\r
-                                                               this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );\r
+                                                               this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );\r
                                                                break;\r
 \r
                                                        // stop()\r
                                                        case 'Stopped':\r
                                                                this.playing && X_Timer_once( 16, this, this.actualPlay );\r
-                                                               return;\r
                                                                \r
                                                                //this.playing = false;\r
-                                                               this._ended  = true;\r
-                                                               this._paused = false;\r
+                                                               //this._ended  = true;\r
+                                                               //this._paused = false;\r
                                                                //this.setCurrentTime( this.startTime );\r
                                                                break;\r
                                                };\r
                                                break;\r
 \r
                                        case X_EVENT_KILL_INSTANCE :\r
-                                               this.playing && this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
+                                               this.playing && this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
                                                this.playing && this.actualPause();\r
                                        \r
                                                if( this._onload ){\r
@@ -254,7 +251,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                // もし kill 後に autoplayTimer で呼ばれても、_closed==true なので平気\r
                                if( this.error ) return;\r
                                if( !this.duration ){\r
-                                       this.autoplay = true;\r
+                                       this._playReserved = true;\r
                                        return;\r
                                };\r
                                \r
@@ -300,7 +297,7 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                                delete this._interval;\r
                                                return X_CALLBACK_UN_LISTEN;\r
                                        };\r
-                                       this.target[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );\r
+                                       this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );\r
                                },\r
                                \r
                                _onEnded : function(){\r
@@ -318,13 +315,13 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                        console.log( '    > ' + time );\r
                                        this._ended && this[ '_rawObject' ].play();\r
                                        this._ended = false;\r
-                                       this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );\r
+                                       this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );\r
                                        this._timerID = X_Timer_once( X_Audio_getEndTime( this ) - time, this, this._onEnded );\r
                                        return;\r
                                };\r
                                \r
                                time -= X_Audio_getEndTime( this );\r
-                               if( time < 0 ){\r
+                               if( time < -50 ){\r
                                        console.log( ' > まだ終わらない ' + time );\r
                                        this._ended && this[ '_rawObject' ].play();\r
                                        this._ended = false;\r
@@ -334,32 +331,30 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                                \r
                                if( this.autoLoop ){\r
                                        console.log( '========= loop?' );\r
-                                       if( !( this.target[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){\r
+                                       if( !( this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){\r
                                                console.log( '========== loopした' );\r
                                                this.looped = true;\r
-                                               this.target[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED );\r
+                                               this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED );\r
                                                this.actualPlay();\r
                                        };\r
                                } else {\r
                                        console.log( '========= pause' );\r
                                        this.actualPause();\r
-                                       this.target[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
+                                       this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );\r
                                };\r
                            };\r
                                },\r
                        \r
                        // SilverlightAudio.pause\r
                        actualPause : function(){\r
-                               if( this.error /*  || !this.playing */ ) return;\r
+                               if( this.error ) return;\r
                                \r
                                this._lastUserAction = 'pause';\r
-                               this.seekTime = this.getActualCurrentTime();\r
                                this.playing  = false;\r
                                this._paused  = true;\r
                                this._ended   = false;\r
                                \r
                                this[ '_rawObject' ].pause();\r
-                               //this.target[ 'dispatch' ]( 'pause' );\r
                        },\r
 \r
                        getActualCurrentTime : function(){\r
@@ -367,6 +362,8 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                        },\r
                        \r
                        afterUpdateState : function( result ){\r
+                               var end, halfway;\r
+                               \r
                                if( result & 3 ){ // seek\r
                        this.actualPlay();\r
                                } else\r
@@ -415,6 +412,8 @@ if( X[ 'Pulgin' ][ 'Silverlight' ] ){
                },\r
 \r
                detect : function( proxy, source, ext ){\r
+                       // TODO source = .mp3#CBR\r
+                       // 得意度で返す\r
                        proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'wma' || ext === 'wav' } );                             \r
                },\r
                \r