Debian Codegraph @

texmf-dist/source/latex/media9/players/VPlayer.mxml

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