OSDN Git Service

Version 0.6.177, bugfix.
[pettanr/clientJs.git] / 0.6.x / js / 07_audio / 03_XSilverlightAudio.js
index 6999b81..aa90277 100644 (file)
  * SilverlLight5 ie6&7(ietester,winxp), ie8(winxp) で動作確認。firefox32 では動作しない。(4以下の方がよい?)\r
  */\r
 \r
-var X_Audio_SLAudioWrapper,\r
-       X_Audio_SLAudio_uid = 0;\r
+var X_SLAudio,\r
+       X_SLAudio_uid = 0;\r
 \r
-if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){\r
+if( X[ 'Pulgin' ][ 'Silverlight' ] ){\r
        \r
        X_TEMP.slaudioInit = function(){\r
                //\r
                // http://blog.yuhiisk.com/archive/2014/12/20/dynamic-loading-and-complete-processing-of-script.html\r
-               var s = document.createElement( '<script id="silverlightaudio" type="text/xaml"></script>' );\r
+               var s;\r
+               \r
+               if( X_UA[ 'IE' ] < 9 ){\r
+                       s = document.createElement( '<script id="silverlightaudio" type="text/xaml"></script>' );\r
+               } else {\r
+                       s = document.createElement( 'script' );\r
+                       s.id   = 'silverlightaudio';\r
+                       s.type = 'text/xaml';\r
+               };\r
                \r
                document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );\r
                s.text = '<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></Canvas>';\r
@@ -29,8 +37,8 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
        };\r
        \r
        // X.Node.inherits はできない。_rawObject は <object> でなく silverlight\r
-       X_Audio_SLAudioWrapper = X_Audio_AbstractAudioBackend[ 'inherits' ](\r
-               'X.AV.SilverlightAudio',\r
+       X_SLAudio = X_AudioBase[ 'inherits' ](\r
+               'X.SilverlightAudio',\r
                X_Class.POOL_OBJECT,\r
                {\r
                        '_rawType'      : X_EventDispatcher_EVENT_TARGET_SILVER_LIGHT,\r
@@ -45,21 +53,21 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                        _lastState      : '',\r
                        _interval       : 0, // setInterval timer id\r
                        \r
-                       'Constructor' : function( target, source, option ){\r
-                               !X_Audio_SLAudio_uid && X_TEMP.slaudioInit();\r
+                       'Constructor' : function( disatcher, source, option ){\r
+                               !X_SLAudio_uid && X_TEMP.slaudioInit();\r
                                \r
                                /*\r
                                 * [Silverlight 2]JavaScriptコードからSilverlightのオブジェクトを利用するには?[C#、VB]\r
                                 * http://www.atmarkit.co.jp/fdotnet/dotnettips/902slobjcallfromjs/slobjcallfromjs.html\r
                                 * このページのサンプルは sl5+firefox32 環境で動いている。xaml を js から利用する形ではなく、.xap を sl4 以下で作るのがよさそう.\r
                                 */\r
-                               \r
-                               // TODO embed\r
-                               this.target      = target || this;\r
+                               this.disatcher   = disatcher || this;\r
                                this._source     = source;\r
                                // X.Audio._slOnload_ は不可\r
-                       this._onload     = 'XAudioSilverlightOnLoad' + ( ++X_Audio_SLAudio_uid );\r
+                       this._onload     = 'XAudioSilverlightOnLoad' + ( ++X_SLAudio_uid );\r
                                this._callback   = window[ this._onload ] = X_Closure_create( this, this.onSLReady );\r
+                               \r
+                               // TODO embed\r
                        this.xnodeObject = X_Node_body\r
                                [ 'create' ]( 'object', {\r
                                                type   : 'application/x-silverlight-2',\r
@@ -114,7 +122,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                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
@@ -122,7 +130,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                        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
+                               this.disatcher[ 'asyncDispatch' ]( X_EVENT_READY );\r
                                \r
                                this.autoplay && X_Timer_once( 16, this, this.actualPlay );\r
                                                break;\r
@@ -151,10 +159,10 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                        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
@@ -171,7 +179,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                                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
@@ -187,9 +195,9 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                                        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
@@ -208,24 +216,23 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                                //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
@@ -252,8 +259,8 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                \r
                                this._lastUserAction = 0 <= this.seekTime ? 'seek' : 'play';\r
                                \r
-                               end   = X_AudioWrapper_getEndTime( this );\r
-                               begin = X_AudioWrapper_getStartTime( this, end, true ) | 0;\r
+                               end   = X_Audio_getEndTime( this );\r
+                               begin = X_Audio_getStartTime( this, end, true ) | 0;\r
 \r
                                // 1 秒以下は指定できないため四捨五入\r
                                begin = ( begin / 1000 | 0 ) * 1000 + ( 500 < begin % 1000 ? 1000 : 0 ); \r
@@ -292,7 +299,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                                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
@@ -300,7 +307,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                        delete this._timerID;\r
                                        \r
                            if( this.playing ){\r
-                               //console.log( '> end ' + X_AudioWrapper_getEndTime( this ) + ' current:' + ( this.getActualCurrentTime() ) );\r
+                               //console.log( '> end ' + X_Audio_getEndTime( this ) + ' current:' + ( this.getActualCurrentTime() ) );\r
                                time = this.getActualCurrentTime();\r
                                \r
                                if( time < this._beginTime ){\r
@@ -310,12 +317,12 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                        console.log( '    > ' + time );\r
                                        this._ended && this[ '_rawObject' ].play();\r
                                        this._ended = false;\r
-                                       this.target[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );\r
-                                       this._timerID = X_Timer_once( X_AudioWrapper_getEndTime( this ) - time, this, this._onEnded );\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_AudioWrapper_getEndTime( this );\r
+                               time -= X_Audio_getEndTime( this );\r
                                if( time < 0 ){\r
                                        console.log( ' > まだ終わらない ' + time );\r
                                        this._ended && this[ '_rawObject' ].play();\r
@@ -326,23 +333,23 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                \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 /*  || !this.playing */ ) return;\r
                                \r
                                this._lastUserAction = 'pause';\r
                                this.seekTime = this.getActualCurrentTime();\r
@@ -351,7 +358,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                                this._ended   = false;\r
                                \r
                                this[ '_rawObject' ].pause();\r
-                               //this.target[ 'dispatch' ]( 'pause' );\r
+                               //this.disatcher[ 'dispatch' ]( 'pause' );\r
                        },\r
 \r
                        getActualCurrentTime : function(){\r
@@ -363,7 +370,7 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                        this.actualPlay();\r
                                } else\r
                                if( result & 1 ){\r
-                                       end     = X_AudioWrapper_getEndTime( this );\r
+                                       end     = X_Audio_getEndTime( this );\r
                                        halfway = end < this.duration;\r
                                        this._timerID && X_Timer_remove( this._timerID );\r
                                        \r
@@ -390,12 +397,15 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                }\r
        );\r
 \r
+       /*\r
        function slerror(){\r
                alert( 'slerror' );\r
-       };\r
+       }; */\r
 \r
        X_Audio_BACKENDS.push( {\r
-               backendName : 'Silverlight Audio',\r
+               backendID   : 8,\r
+               \r
+               backendName : 'Silverlight',\r
 \r
                canPlay : {\r
                        'mp3' : true,\r
@@ -404,11 +414,10 @@ if( X[ 'Pulgin' ][ 'SilverlightEnabled' ] ){
                },\r
 \r
                detect : function( proxy, source, ext ){\r
-                       var ok = ext === 'mp3' || ext === 'wma' || ext === 'wav';\r
-                       proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ok } );                          \r
+                       proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : ext === 'mp3' || ext === 'wma' || ext === 'wav' } );                             \r
                },\r
                \r
-               klass : X_Audio_SLAudioWrapper\r
+               klass : X_SLAudio\r
                \r
        } );\r
 \r