Debian Codegraph @

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

raw
1 <?xml version="1.0"?>
2 <!-- -->
3 <!-- Adobe Flex 3 source file of APlayer9.swf, -->
4 <!-- a FlashPlayer-9 compatible component for playing -->
5 <!-- MP3 audio files and streams. -->
6 <!-- -->
7 <!-- version 20150601 -->
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 xmlns:mx="http://www.adobe.com/2006/mxml"
23 preinitialize="initialise(this.parameters);"
24 applicationComplete="initSound();addEventListeners();"
25 creationComplete="initCallBacks();initContext();"
26 mouseDown="pause();setFocus();"
27 mouseUp="play();"
28 backgroundAlpha="0"
29 paddingTop="0" paddingBottom="0"
30 paddingLeft="0" paddingRight="0"
31 layout="absolute" clipContent="false"
32 >
33
34 <mx:Script>
35 <![CDATA[
36 [Bindable] private var source:String;
37 [Bindable] private var policy:String=null;
38 [Bindable] private var autoPlay:Boolean=false;
39 [Bindable] private var loop:Boolean=false;
40 [Bindable] private var vol:Number=0.75;
41 [Bindable] private var pan:Number=0;
42 [Bindable] private var hideBar:Boolean=false;
43 [Bindable] private var txtAlign:String;
44
45 private var snd:Sound;
46 private var id3:ID3Info;
47 private var sndCh:SoundChannel;
48 private var sndTr:SoundTransform;
49 private var playResumePos:Number = 0;
50 private var pauseAtPos:Number = -1;
51 private var toBePaused:Boolean = false;
52 private var plyng:Boolean = false;
53 private var muted:Boolean = false;
54 private var lastVol:Number;
55
56 private var deltaSeek:Number;
57 private var curTime:Number;
58 private var keyPressed:Boolean=false;
59 private var mouseIsOver:Boolean=false;
60
61 import flash.external.*;
62 private function initialise(flashVars:Object):void {
63 source=flashVars.source;
64 if(flashVars.policy) policy=flashVars.policy;
65 if(flashVars.autoPlay=='true') autoPlay=true;
66 if(flashVars.loop=='true') loop=true;
67 if(flashVars.volume) vol=Number(flashVars.volume);
68 if(flashVars.balance) pan=Number(flashVars.balance);
69 if(flashVars.hideBar=='true') hideBar=true;
70 }
71
72 import mx.controls.Alert;
73
74 private function initSound():void {
75 snd = new Sound(); id3=null;
76 sndTr = new SoundTransform(vol, pan);
77 snd.addEventListener(Event.ID3, onID3Info);
78 snd.addEventListener(IOErrorEvent.IO_ERROR, onError);
79 snd.addEventListener(ProgressEvent.PROGRESS, onProgress);
80 snd.addEventListener(Event.COMPLETE, onComplete);
81 if(policy) Security.loadPolicyFile(policy);
82 snd.load(new URLRequest(source), new SoundLoaderContext(1000, true));
83 if(autoPlay) play();
84 }
85
86 private function onMouseOver(e:MouseEvent):void {
87 mouseIsOver=true;
88 fadeEffect.end();
89 playProgress.alpha=caption.alpha=1.0;
90 caption.visible=!hideBar;
91 }
92
93 private function onMouseOut(e:MouseEvent):void {
94 mouseIsOver=false;
95 fadeEffect.play();
96 }
97
98 private function onKeyDown(e:KeyboardEvent):void {
99 switch(e.keyCode) {
100 case 32: //space bar
101 playPause();
102 break;
103 case 36: //home
104 pause();
105 playResumePos=(0);
106 break;
107 case 35: //end
108 if(playProgress.indeterminate) break;
109 pause();
110 playResumePos=(snd.length);
111 break;
112 case 37: //<--
113 fadeEffect.end();
114 playProgress.alpha=caption.alpha=1.0;
115 caption.visible=!hideBar;
116 if(e.ctrlKey){
117 pan=Math.max(-1,pan-0.025);
118 balance(pan);
119 break;
120 }
121 if(!keyPressed){
122 deltaSeek=Math.max(100,snd.length/10000);
123 if(plyng)
124 curTime=sndCh.position;
125 else
126 curTime=playResumePos;
127 }
128 keyPressed=true;
129 playResumePos=Math.max(0,curTime-deltaSeek);
130 if(plyng) seek(playResumePos/1000);
131 deltaSeek*=1.1;
132 break;
133 case 39: //-->
134 fadeEffect.end();
135 playProgress.alpha=caption.alpha=1.0;
136 caption.visible=!hideBar;
137 if(e.ctrlKey){
138 pan=Math.min(1,pan+0.025);
139 balance(pan);
140 break;
141 }
142 if(!keyPressed){
143 deltaSeek=Math.max(100,snd.length/10000);
144 if(plyng)
145 curTime=sndCh.position;
146 else
147 curTime=playResumePos;
148 }
149 keyPressed=true;
150 playResumePos=Math.min(snd.length-10,curTime+deltaSeek);
151 seek(playResumePos/1000);
152 deltaSeek*=1.1;
153 break;
154 case 38:
155 vol=Math.min(1,vol+0.025);
156 volume(vol);
157 break;
158 case 40:
159 if(e.ctrlKey){
160 pan=0;
161 balance(pan);
162 break;
163 }
164 vol=Math.max(0,vol-0.025);
165 volume(vol);
166 break;
167 default:
168 if(e.charCode==109) mute(); //`m'
169 }
170 }
171
172 private function onKeyUp(e:KeyboardEvent):void {
173 switch(e.keyCode) {
174 case 37: //<--
175 case 39: //-->
176 deltaSeek=Math.max(100,snd.length/10000);
177 keyPressed=false;
178 if (!mouseIsOver) fadeEffect.play();
179 break;
180 }
181 }
182
183 private function formatLabel(s:Number):String {
184 s/=1000;
185 var hrs:Number = Math.floor(s / 3600);
186 var min:Number = Math.floor(s / 60 % 60);
187 var sec:Number = Math.floor(s % 60);
188 var fmtd:String='';
189 if(hrs>0) fmtd = String(hrs)+':';
190 if(hrs>0 && min <10) fmtd+='0';
191 fmtd += String(min)+':';
192 if(sec<10) fmtd+='0';
193 fmtd += String(sec);
194 txtAlign="center";
195 try{
196 if(id3.songName)
197 fmtd += ' '+ String.fromCharCode(0x2014) + ' ' + id3.songName;
198 if(id3.artist) fmtd += ' | ' + id3.artist;
199 if(id3.album) fmtd += ' | ' + id3.album;
200 if(id3) txtAlign="start";
201 }catch(e:Object){}
202 return fmtd;
203 }
204
205 private function addEventListeners():void {
206 this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
207 this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
208 this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
209 this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
210 this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
211 }
212
213 private function setSource(s:String):void {
214 pause();
215 source=s;
216 initSound();
217 pause();seek(0);
218 }
219
220 private function loadPolicy(p:String):void {policy=p;}
221
222 private function play(p:Number=-1):void {
223 if(p>=0) seek(p);
224 if(plyng) return;
225 try{sndCh = snd.play(playResumePos, 0, sndTr);}
226 catch(e:Error){Alert.show(e.message,'Error');}
227 sndCh.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
228 plyng = true;
229 }
230
231 private function pause(p:Number=-1):void {
232 if(p>=0){pauseAtPos=p*1000;return;}
233 if(!plyng) return;
234 playResumePos = sndCh.position;
235 sndCh.stop();
236 plyng = false;
237 }
238
239 private function playPause():void {
240 if(plyng) pause(); else play();
241 }
242
243 private function seek(p:Number):void {
244 playResumePos = p*1000;
245 if(!plyng) return;
246 sndCh.stop();
247 plyng = false;
248 play();
249 }
250
251 private function rewind():void {
252 seek(0);
253 }
254
255 private function volume(v:Number):void {
256 sndTr.volume = v;
257 sndCh.soundTransform=sndTr;
258 }
259
260 private function mute():void {
261 if(muted) {
262 if(lastVol==0) lastVol=0.75;
263 volume(lastVol);
264 muted=false;
265 }
266 else {
267 lastVol = sndTr.volume
268 volume(0);
269 muted=true;
270 }
271 }
272
273 private function balance(p:Number):void {
274 sndTr.pan = p;
275 sndCh.soundTransform=sndTr;
276 }
277
278 private function currentTime():Number {
279 return sndCh.position/1000;
280 }
281
282 private function playing():Boolean {
283 return plyng;
284 }
285
286 private function duration():Number {
287 return snd.length/1000;
288 }
289
290 private function ismuted():Boolean {
291 return muted;
292 }
293
294 private function initCallBacks():void {
295 ExternalInterface.addCallback("play", play);
296 ExternalInterface.addCallback("pause", pause);
297 ExternalInterface.addCallback("playPause", playPause);
298 ExternalInterface.addCallback("seek", seek);
299 ExternalInterface.addCallback("rewind", rewind);
300 ExternalInterface.addCallback("volume", volume);
301 ExternalInterface.addCallback("balance", balance);
302 ExternalInterface.addCallback("mute", mute);
303 ExternalInterface.addCallback("setSource", setSource);
304 ExternalInterface.addCallback("loadPolicy", loadPolicy);
305 ExternalInterface.addCallback("currentTime", currentTime);
306 ExternalInterface.addCallback("duration", duration);
307 ExternalInterface.addCallback("playing", playing);
308 ExternalInterface.addCallback("muted", ismuted);
309 }
310
311 private function initContext():void {
312 this.contextMenu.hideBuiltInItems();
313
314 var itemPlayPause:ContextMenuItem = new ContextMenuItem("N.N.");
315 this.contextMenu.customItems.push(itemPlayPause);
316 itemPlayPause.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
317 function(e:ContextMenuEvent):void{playPause();});
318
319 var itemRewind:ContextMenuItem = new ContextMenuItem("Rewind, [Home]");
320 this.contextMenu.customItems.push(itemRewind);
321 itemRewind.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
322 function(e:ContextMenuEvent):void{pause();playResumePos=(0);});
323
324 var itemGotoEnd:ContextMenuItem=new ContextMenuItem("Goto End, [End]");
325 this.contextMenu.customItems.push(itemGotoEnd);
326 itemGotoEnd.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
327 function(e:ContextMenuEvent):void{
328 if(playProgress.indeterminate) return;
329 pause();playResumePos=(snd.length);});
330
331 var itemMute:ContextMenuItem = new ContextMenuItem("N.N.");
332 this.contextMenu.customItems.push(itemMute);
333 itemMute.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
334 function(e:ContextMenuEvent):void{mute();});
335
336 this.contextMenu.customItems.push(
337 new ContextMenuItem("via keyboard:", true, false, true));
338 this.contextMenu.customItems.push(
339 new ContextMenuItem("Seek, [\u2190]/[\u2192]", false, false, true));
340 this.contextMenu.customItems.push(
341 new ContextMenuItem("Volume, [\u2191]/[\u2193]", false, false, true));
342 this.contextMenu.customItems.push(
343 new ContextMenuItem("Balance, [Ctrl]+[\u2190]/[\u2193]/[\u2192]",
344 false, false, true));
345
346 this.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,
347 function(e:ContextMenuEvent):void{
348 itemPlayPause.caption=(plyng ? "Pause" : "Play")+", [Space]";
349 itemMute.caption=(muted ? "Unmute" : "Mute")+", [m]";}
350 );
351 }
352
353 private function onSoundComplete(e:Event):void {
354 plyng = false;
355 playResumePos = 0;
356 if(loop) play();
357 }
358
359 private function onComplete(e:Event):void {
360 playProgress.indeterminate=false;
361 }
362
363 private function onProgress(e:ProgressEvent):void {
364 playProgress.indeterminate=true;
365 }
366
367 private function onEnterFrame(e:Event):void {
368 if(!playProgress.indeterminate) {
369 if(plyng) {
370 playProgress.setProgress(sndCh.position,snd.length);
371 caption.text=formatLabel(sndCh.position);
372 } else {
373 playProgress.setProgress(playResumePos,snd.length);
374 caption.text=formatLabel(playResumePos);
375 }
376 }else{
377 if(plyng) {
378 playProgress.setProgress(Math.random(),1);
379 caption.text=formatLabel(sndCh.position);
380 } else {
381 playProgress.setProgress(snd.bytesLoaded,snd.bytesTotal);
382 caption.text=formatLabel(playResumePos);
383 }
384 }
385 if(plyng&&pauseAtPos>=0&&sndCh.position<pauseAtPos)
386 toBePaused=true;
387 if(
388 plyng&&pauseAtPos>=0&&
389 sndCh.position>=pauseAtPos&&toBePaused
390 ){
391 pause();
392 pauseAtPos=-1;
393 toBePaused=false;
394 }
395 }
396
397 private function onID3Info(e:Event):void {id3 = e.target.id3;}
398
399 private function onError(e:ErrorEvent):void {
400 Alert.show(e.type, e.text);
401 }
402 ]]>
403 </mx:Script>
404
405 <mx:Fade id="fadeEffect" target="{playProgress}" alphaFrom="1.0" alphaTo="0"
406 effectEnd="caption.visible=false" duration="2000"/>
407
408 <mx:ProgressBar width="100%" height="100%" mode="manual"
409 labelPlacement="center" label="" id="playProgress"
410 visible="{!hideBar}"
411 />
412
413 <mx:Label id="caption" width="100%" verticalCenter="0"
414 paddingTop="2" fontWeight="bold" visible="{!hideBar}"
415 textAlign="{txtAlign}" paddingLeft="5"
416 />
417 </mx:Application>