1 // https://msdn.microsoft.com/ja-jp/library/cc410695.aspx
2 // Windows Media Player コントロール Version 6.4
4 // http://www.tohoho-web.com/wwwmmd2.htm
6 // http://devedge.primedirective.net/viewsource/2003/windows-media-in-netscape/index.html
10 if( X_Pulgin_WMP_VERSION ){ // IETester で 6.x は不可
11 X_WMPAudio = X_AudioBase[ 'inherits' ](
25 'Constructor' : function( disatcher, source, option ){
26 this.disatcher = disatcher || this;
27 this._source = source;
29 if( 7 <= X_Pulgin_WMP_VERSION ){
30 this.xnodeObject = X_Node_systemNode[ 'create' ]( 'object', {
31 'classID' : 'CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6',
35 X_UA[ 'IE55' ] ? '' : '<param name="uiMode" value="none">'
36 //+ '<param name="URL" value="' + source + '">'
37 //+ '<param name="AutoStart" value="' + option.autoplay + '">'
40 this.xnodeObject = X_Node_systemNode[ 'create' ]( 'object', {
41 classID : 'CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95',
45 X_UA[ 'IE55' ] ? '' : '<param name="ShowControls" value="false">'
46 //+ '<param name="FileName" value="' + source + '">'
47 //+ '<param name="AutoStart" value="' + option.autoplay + '">'
52 this.setState( option );
54 X_ViewPort[ 'listenOnce' ]( X_EVENT_AFTER_UPDATE, this );
55 this[ 'listenOnce' ]( X_EVENT_KILL_INSTANCE );
58 handleEvent : function( e ){
60 case X_EVENT_AFTER_UPDATE :
62 if( 7 <= X_Pulgin_WMP_VERSION ){
63 this._wmp = this.xnodeObject[ '_rawObject' ];
64 this._wmp[ 'URL' ] = this._source;
65 this.wmp = this._wmp[ 'controls' ];
67 this.wmp = this.xnodeObject[ '_rawObject' ];
68 this.wmp[ 'FileName' ] = this._source;
70 this._timerID = X_Timer_add( 100, 0, this, this._onTimer );
73 case X_EVENT_KILL_INSTANCE :
74 this.playing && this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );
75 this.playing && this.actualPause();
77 this.xnodeObject[ 'kill' ]();
83 actualPlay : function(){
84 var begin, offset, end;
86 if( this._readyState < 2 ){
87 this._playReserved = true;
91 end = X_Audio_getEndTime( this );
92 begin = this._beginTime = X_Audio_getStartTime( this, end, true ) | 0;
94 console.log( '[play] ' + begin + ' -> ' + end );
102 this._seekDirection = this.getActualCurrentTime() < begin ? 1 : -1;
105 // 1 秒以下は指定できないため四捨五入
106 //begin = ( begin / 1000 | 0 ) * 1000 + ( 500 < begin % 1000 ? 1000 : 0 );
107 this.wmp[ 'CurrentPosition' ] = begin / 1000;
109 if( !this._timerID ) this._timerID = X_Timer_add( 100, 0, this, this._onTimer );
112 _onTimer : function(){
116 if( this._readyState === 1 ){
117 if( 7 <= X_Pulgin_WMP_VERSION ){
118 progress = this._wmp[ 'network' ][ 'downloadProgress' ];
120 progress = this.wmp[ 'BufferingProgress' ];
122 if( progress < 100 ){
123 this.disatcher[ 'dispatch' ]( { type : X_EVENT_PROGRESS, 'percent' : progress } );
125 this._readyState = 2;
126 if( 7 <= X_Pulgin_WMP_VERSION ){
127 this.duration = this._wmp[ 'currentMedia' ].duration * 1000 | 0;
129 this.duration = this.wmp[ 'Duration' ] * 1000 | 0;
131 this.disatcher[ 'dispatch' ]( X_EVENT_READY );
136 time = this.getActualCurrentTime();
139 if( this._seekDirection ){
140 if( this._seekDirection === 1 ? ( time < this._beginTime ) : ( this._lastCurrentTime <= time ) ){
141 this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_SEEKING );
144 delete this._seekDirection;
146 if( time === this._lastCurrentTime ){
147 this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_WAITING );
150 this._lastCurrentTime = time;
153 if( time - X_Audio_getEndTime( this ) < -50 ){
154 this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_PLAYING );
160 if( !( this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_BEFORE_LOOP ) & X_CALLBACK_PREVENT_DEFAULT ) ){
162 this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_LOOPED );
167 this.disatcher[ 'dispatch' ]( X_EVENT_MEDIA_ENDED );
168 delete this._timerID;
169 return X_CALLBACK_UN_LISTEN;
175 actualPause : function(){
176 this.playing = false;
177 this._timerID && X_Timer_remove( this._timerID );
178 delete this._timerID;
183 setVolume : function(){
184 if( 7 <= X_Pulgin_WMP_VERSION ){
185 this._wmp[ 'settings' ][ 'Volume' ] = this.gain * 100;
187 this.wmp[ 'Volume' ] = ( 1 - this.gain ) * 10000;
191 getActualCurrentTime : function(){
192 return this.wmp[ 'CurrentPosition' ] * 1000 | 0;
195 afterUpdateState : function( result ){
196 if( result & 3 ){ // seek
207 X_Audio_BACKENDS.push( {
210 backendName : 'WMP' + X_Pulgin_WMP_VERSION,
226 detect : function( proxy, source, ext ){
227 proxy[ 'asyncDispatch' ]( { type : X_EVENT_COMPLETE, canPlay : 0 <= 'mp3 m4a wma wav midi snd au aiff aicf'.indexOf( ext ) } );