| 1 |
<?xml version="1.0"?> |
| 2 |
<!-- --> |
| 3 |
<!-- Adobe Flex 3 source file of VPlayer9.swf, --> |
| 4 |
<!-- a FlashPlayer-9 compatible component for playing --> |
| 5 |
<!-- FLV and MP4/H.264 video files and streams. --> |
| 6 |
<!-- --> |
| 7 |
<!-- version 20150729 --> |
| 8 |
<!-- --> |
| 9 |
<!-- Copyright (C) 2012-today Alexander Grahn --> |
| 10 |
<!-- --> |
| 11 |
<!-- This work may be distributed and/or modified under the --> |
| 12 |
<!-- conditions of the LaTeX Project Public License. --> |
| 13 |
<!-- --> |
| 14 |
<!-- The latest version of this license is in --> |
| 15 |
<!-- http://www.latex-project.org/lppl.txt --> |
| 16 |
<!-- --> |
| 17 |
<!-- This work has the LPPL maintenance status `maintained'. --> |
| 18 |
<!-- --> |
| 19 |
<!-- The current maintainer of this work is A. Grahn. --> |
| 20 |
<!-- --> |
| 21 |
|
| 22 |
<mx:Application |
| 23 |
xmlns:mx="http://www.adobe.com/2006/mxml" |
| 24 |
preinitialize="initialise(this.parameters);" |
| 25 |
applicationComplete="initApp();" |
| 26 |
backgroundAlpha="0" |
| 27 |
paddingTop="0" paddingBottom="0" |
| 28 |
paddingLeft="0" paddingRight="0" |
| 29 |
layout="absolute" clipContent="false" |
| 30 |
> |
| 31 |
<mx:Script> |
| 32 |
<![CDATA[ |
| 33 |
[Bindable] private var source:String; |
| 34 |
[Bindable] private var autoPlay:Boolean=false; |
| 35 |
[Bindable] private var loop:Boolean=false; |
| 36 |
[Bindable] private var vol:Number=0.75; |
| 37 |
[Bindable] private var keepAspect:Boolean=true; |
| 38 |
private var vidComplete:Boolean=false; |
| 39 |
private var deltaSeek:Number; |
| 40 |
private var playheadTime:Number; |
| 41 |
private var newPos:Number; |
| 42 |
private var keyPressed:Boolean=false; |
| 43 |
private var muted:Boolean=false; |
| 44 |
private var lastVolume:Number; |
| 45 |
private var pauseAtPos:Number = -1; |
| 46 |
private var toBePaused:Boolean = false; |
| 47 |
|
| 48 |
import flash.external.*; |
| 49 |
private function initialise(flashVars:Object):void { |
| 50 |
source=flashVars.source; |
| 51 |
if(flashVars.autoPlay=='true') autoPlay=true; |
| 52 |
if(flashVars.loop=='true') loop=true; |
| 53 |
if(flashVars.volume) vol=Number(flashVars.volume); |
| 54 |
if(flashVars.scaleMode && flashVars.scaleMode!='letterbox') keepAspect=false; |
| 55 |
} |
| 56 |
|
| 57 |
private function onProgress(event:ProgressEvent):void { |
| 58 |
if (event.bytesTotal) event.target.visible=true; |
| 59 |
else event.target.visible=false; |
| 60 |
} |
| 61 |
|
| 62 |
import mx.events.VideoEvent; |
| 63 |
//import flash.events.VideoEvent; |
| 64 |
import mx.controls.Alert; |
| 65 |
private function onStateChange(event:mx.events.VideoEvent):void { |
| 66 |
vidComplete=false; |
| 67 |
if(event.state=='connectionError') |
| 68 |
Alert.show('Unable to play \''+event.target.source+'\'','Error'); |
| 69 |
} |
| 70 |
|
| 71 |
private function onKeyDown(e:KeyboardEvent):void { |
| 72 |
switch(e.keyCode) { |
| 73 |
case 32: //space bar |
| 74 |
playPause(); |
| 75 |
break; |
| 76 |
case 36: //home |
| 77 |
vidDisp.pause(); |
| 78 |
vidDisp.playheadTime=0; |
| 79 |
break; |
| 80 |
case 35: //end |
| 81 |
if(vidDisp.bytesTotal){ |
| 82 |
vidDisp.pause(); |
| 83 |
vidDisp.playheadTime=vidDisp.totalTime-0.1; |
| 84 |
} |
| 85 |
break; |
| 86 |
case 37: //<-- |
| 87 |
fadeEffect.end(); |
| 88 |
playProgress.alpha=0.5; |
| 89 |
playProgress.visible=true; |
| 90 |
if(!keyPressed){ |
| 91 |
deltaSeek=Math.max(1,vidDisp.totalTime/1000); |
| 92 |
playheadTime=vidDisp.playheadTime; |
| 93 |
} |
| 94 |
keyPressed=true; |
| 95 |
newPos=Math.max(0,playheadTime-deltaSeek); |
| 96 |
playProgress.setProgress(newPos,vidDisp.totalTime); |
| 97 |
playProgress.label=formatTime(newPos); |
| 98 |
vidDisp.playheadTime=newPos; |
| 99 |
deltaSeek*=1.1; |
| 100 |
break; |
| 101 |
case 39: //--> |
| 102 |
fadeEffect.end(); |
| 103 |
playProgress.alpha=0.5; |
| 104 |
playProgress.visible=true; |
| 105 |
if(!keyPressed){ |
| 106 |
deltaSeek=Math.max(1,vidDisp.totalTime/1000); |
| 107 |
playheadTime=vidDisp.playheadTime; |
| 108 |
} |
| 109 |
keyPressed=true; |
| 110 |
newPos=Math.min(vidDisp.totalTime-0.1,playheadTime+deltaSeek); |
| 111 |
playProgress.setProgress(newPos,vidDisp.totalTime); |
| 112 |
playProgress.label=formatTime(newPos); |
| 113 |
vidDisp.playheadTime=newPos; |
| 114 |
deltaSeek*=1.1; |
| 115 |
break; |
| 116 |
case 38: |
| 117 |
vol=Math.min(1,vol+0.025); |
| 118 |
volume(vol); |
| 119 |
break; |
| 120 |
case 40: |
| 121 |
vol=Math.max(0,vol-0.025); |
| 122 |
volume(vol); |
| 123 |
break; |
| 124 |
default: |
| 125 |
if(e.charCode==109) mute(); //`m' |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
private function onKeyUp(e:KeyboardEvent):void { |
| 130 |
switch(e.keyCode) { |
| 131 |
case 37: //<-- |
| 132 |
case 39: //--> |
| 133 |
deltaSeek=Math.max(1,vidDisp.totalTime/1000); |
| 134 |
keyPressed=false; |
| 135 |
fadeEffect.play(); |
| 136 |
break; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
private function onPlayheadUpdate(e:Event):void { |
| 141 |
if(vidDisp.playing&&pauseAtPos>=0&&vidDisp.playheadTime<pauseAtPos) |
| 142 |
toBePaused=true; |
| 143 |
if( |
| 144 |
vidDisp.playing&&pauseAtPos>=0&& |
| 145 |
vidDisp.playheadTime>=pauseAtPos&&toBePaused |
| 146 |
){ |
| 147 |
pause(); |
| 148 |
pauseAtPos=-1; |
| 149 |
toBePaused=false; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
private function play(p:Number=-1):void { |
| 154 |
if(p>=0) seek(p); |
| 155 |
if(vidComplete){seek(0);}vidDisp.play(); |
| 156 |
} |
| 157 |
|
| 158 |
private function pause(p:Number=-1):void { |
| 159 |
if(p>=0){pauseAtPos=p;return;} |
| 160 |
vidDisp.pause(); |
| 161 |
} |
| 162 |
|
| 163 |
private function playPause():void { |
| 164 |
if(vidDisp.playing) vidDisp.pause(); else vidDisp.play(); |
| 165 |
} |
| 166 |
|
| 167 |
private function seek(p:Number):void { |
| 168 |
vidDisp.playheadTime=p; |
| 169 |
} |
| 170 |
|
| 171 |
private function rewind():void { |
| 172 |
vidDisp.playheadTime=0; |
| 173 |
} |
| 174 |
|
| 175 |
private function volume(v:Number):void { |
| 176 |
muted=false; |
| 177 |
vidDisp.volume = v; |
| 178 |
} |
| 179 |
|
| 180 |
private function mute():void { |
| 181 |
if(muted) { |
| 182 |
if (lastVolume==0) volume(0.75); |
| 183 |
else volume(lastVolume); |
| 184 |
} |
| 185 |
else { |
| 186 |
muted=true;lastVolume=vidDisp.volume;vidDisp.volume=0; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
private function setSource(s:String):void { |
| 191 |
vidDisp.pause();vidDisp.source = s; |
| 192 |
vidDisp.play();vidDisp.pause(); |
| 193 |
vidDisp.playheadTime=0; |
| 194 |
} |
| 195 |
|
| 196 |
private function formatTime(s:Number):String { |
| 197 |
var hrs:Number = Math.floor(s / 3600); |
| 198 |
var min:Number = Math.floor(s / 60 % 60); |
| 199 |
var sec:Number = Math.floor(s % 60); |
| 200 |
|
| 201 |
var fmtd:String=''; |
| 202 |
|
| 203 |
if (hrs>0) fmtd = String(hrs)+':'; |
| 204 |
|
| 205 |
if (hrs>0 && min <10) fmtd+='0'; |
| 206 |
fmtd += String(min)+':'; |
| 207 |
|
| 208 |
if (sec<10) fmtd+='0'; |
| 209 |
fmtd += String(sec); |
| 210 |
|
| 211 |
return fmtd; |
| 212 |
} |
| 213 |
|
| 214 |
private function currentTime():Number { |
| 215 |
return vidDisp.playheadTime; |
| 216 |
} |
| 217 |
|
| 218 |
private function playing():Boolean { |
| 219 |
return vidDisp.playing; |
| 220 |
} |
| 221 |
|
| 222 |
private function duration():Number { |
| 223 |
return vidDisp.totalTime; |
| 224 |
} |
| 225 |
|
| 226 |
private function ismuted():Boolean { |
| 227 |
return muted; |
| 228 |
} |
| 229 |
|
| 230 |
private function initApp():void { |
| 231 |
this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); |
| 232 |
this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp); |
| 233 |
ExternalInterface.addCallback("play", play); |
| 234 |
ExternalInterface.addCallback("pause", pause); |
| 235 |
ExternalInterface.addCallback("playPause", playPause); |
| 236 |
ExternalInterface.addCallback("seek", seek); |
| 237 |
ExternalInterface.addCallback("rewind", rewind); |
| 238 |
ExternalInterface.addCallback("volume", volume); |
| 239 |
ExternalInterface.addCallback("mute", mute); |
| 240 |
ExternalInterface.addCallback("setSource", setSource); |
| 241 |
ExternalInterface.addCallback("currentTime", currentTime); |
| 242 |
ExternalInterface.addCallback("duration", duration); |
| 243 |
ExternalInterface.addCallback("playing", playing); |
| 244 |
ExternalInterface.addCallback("muted", ismuted); |
| 245 |
|
| 246 |
var itemPlayPause:ContextMenuItem = new ContextMenuItem("N.N."); |
| 247 |
this.contextMenu.customItems.push(itemPlayPause); |
| 248 |
itemPlayPause.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, |
| 249 |
function(e:ContextMenuEvent):void{playPause();}); |
| 250 |
|
| 251 |
var itemRewind:ContextMenuItem = new ContextMenuItem("Rewind, [Home]"); |
| 252 |
this.contextMenu.customItems.push(itemRewind); |
| 253 |
itemRewind.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, |
| 254 |
function(e:ContextMenuEvent):void{vidDisp.pause();seek(0);}); |
| 255 |
|
| 256 |
var itemGotoEnd:ContextMenuItem = new ContextMenuItem("Goto End, [End]"); |
| 257 |
this.contextMenu.customItems.push(itemGotoEnd); |
| 258 |
itemGotoEnd.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, |
| 259 |
function(e:ContextMenuEvent):void{if(vidDisp.bytesTotal){ |
| 260 |
vidDisp.pause(); |
| 261 |
vidDisp.playheadTime=vidDisp.totalTime-0.1;}}); |
| 262 |
|
| 263 |
var itemMute:ContextMenuItem = new ContextMenuItem("N.N."); |
| 264 |
this.contextMenu.customItems.push(itemMute); |
| 265 |
itemMute.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, |
| 266 |
function(e:ContextMenuEvent):void{mute();}); |
| 267 |
|
| 268 |
this.contextMenu.customItems.push( |
| 269 |
new ContextMenuItem("via keyboard:", true, false, true)); |
| 270 |
this.contextMenu.customItems.push( |
| 271 |
new ContextMenuItem("Seek, [\u2190]/[\u2192]", false, false, true)); |
| 272 |
this.contextMenu.customItems.push( |
| 273 |
new ContextMenuItem("Volume, [\u2191]/[\u2193]", false, false, true)); |
| 274 |
|
| 275 |
this.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, |
| 276 |
function(e:ContextMenuEvent):void{ |
| 277 |
itemPlayPause.caption=(vidDisp.playing ? "Pause" : "Play")+", [Space]"; |
| 278 |
itemMute.caption=(muted ? "Unmute" : "Mute")+", [m]";} |
| 279 |
); |
| 280 |
} |
| 281 |
]]> |
| 282 |
</mx:Script> |
| 283 |
|
| 284 |
<mx:Fade id="fadeEffect" target="{playProgress}" alphaFrom="0.5" alphaTo="0" duration="2000" |
| 285 |
effectEnd="playProgress.label=''" |
| 286 |
/> |
| 287 |
|
| 288 |
<mx:VideoDisplay |
| 289 |
id="vidDisp" |
| 290 |
width="100%" height="100%" maintainAspectRatio="{keepAspect}" |
| 291 |
backgroundAlpha="0" borderThickness="0" |
| 292 |
source="{source}" volume="{vol}" |
| 293 |
autoPlay="{autoPlay}" autoRewind="{loop}" |
| 294 |
stateChange="onStateChange(event);" |
| 295 |
complete="vidComplete=true;" |
| 296 |
rewind="vidDisp.play();" |
| 297 |
playheadUpdate="onPlayheadUpdate(event);" |
| 298 |
/> |
| 299 |
|
| 300 |
<mx:ProgressBar width="100%" mode="polled" source="vidDisp" |
| 301 |
horizontalCenter="0" bottom="0" labelPlacement="center" |
| 302 |
id="loadingProgress" alpha="0.5" |
| 303 |
complete="loadingProgress.visible=false;" |
| 304 |
progress="onProgress(event)" |
| 305 |
/> |
| 306 |
|
| 307 |
<mx:ProgressBar width="100%" mode="manual" |
| 308 |
horizontalCenter="0" bottom="0" labelPlacement="center" |
| 309 |
id="playProgress" alpha="0.5" |
| 310 |
visible="false" |
| 311 |
/> |
| 312 |
|
| 313 |
<mx:Button alpha="0" width="100%" height="100%" cornerRadius="0" |
| 314 |
paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0" |
| 315 |
mouseDown="vidDisp.pause();" |
| 316 |
mouseUp="if(vidComplete) vidDisp.playheadTime=0;vidDisp.play();" |
| 317 |
/> |
| 318 |
</mx:Application> |