summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml')
-rw-r--r--Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml376
1 files changed, 248 insertions, 128 deletions
diff --git a/Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml b/Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml
index cffab803f7e..86c62753d3b 100644
--- a/Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml
+++ b/Master/texmf-dist/doc/latex/media9/files/players/APlayer.mxml
@@ -4,7 +4,7 @@
<!-- a FlashPlayer-10 compatible component for playing -->
<!-- MP3 audio files and streams. -->
<!-- -->
-<!-- version 20120425 -->
+<!-- version 20121002 -->
<!-- -->
<!-- -->
<!-- The free Adobe Flex 4 SDK is required to compile -->
@@ -40,154 +40,274 @@
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
preinitialize="initialise(FlexGlobals.topLevelApplication.parameters);"
- applicationComplete="initSound();addEventListener(Event.ENTER_FRAME, onEnterFrame);"
+ applicationComplete="initSound();addeventlisteners();"
creationComplete="initCallBacks();"
- mouseDown="pause();"
+ mouseDown="pause();setFocus();"
mouseUp="play();"
>
- <fx:Script>
- <![CDATA[
- [Bindable] private var source:String;
- [Bindable] private var autoPlay:Boolean=false;
- [Bindable] private var loop:Boolean=false;
- [Bindable] private var vol:Number=0.75;
- [Bindable] private var balance:Number=0;
-
- private var snd:Sound;
- private var sndCh:SoundChannel;
- private var sndTr:SoundTransform;
- private var playResumePosition:Number = 0;
- private var playing:Boolean = false;
- private var muted:Boolean = false;
- private var lastVol:Number;
-
- import mx.core.FlexGlobals;
- private function initialise(flashVars:Object):void {
- source=flashVars.source;
- if(flashVars.autoPlay){autoPlay=(flashVars.autoPlay=='true')}
- if(flashVars.loop){loop=(flashVars.loop=='true')}
- if(flashVars.volume){vol=Number(flashVars.volume)}
- if(flashVars.balance){balance=Number(flashVars.balance)}
- }
+ <fx:Script>
+ <![CDATA[
+ [Bindable] private var source:String;
+ [Bindable] private var autoPlay:Boolean=false;
+ [Bindable] private var loop:Boolean=false;
+ [Bindable] private var vol:Number=0.75;
+ [Bindable] private var pan:Number=0;
- import mx.controls.Alert;
- private function initSound():void {
- snd = new Sound(new URLRequest(source));
- sndTr = new SoundTransform(vol, balance);
+ private var snd:Sound;
+ private var sndCh:SoundChannel;
+ private var sndTr:SoundTransform;
+ private var playResumePosition:Number = 0;
+ private var playing:Boolean = false;
+ private var muted:Boolean = false;
+ private var lastVol:Number;
- snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
- snd.addEventListener(ProgressEvent.PROGRESS, progressHandler);
- snd.addEventListener(Event.COMPLETE, completeHandler);
+ private var deltaSeek:Number;
+ private var currentTime:Number;
+ private var keyPressed:Boolean=false;
- if(autoPlay) play();
- }
+ import mx.core.FlexGlobals;
+ private function initialise(flashVars:Object):void {
+ source=flashVars.source;
+ if(flashVars.autoPlay){autoPlay=(flashVars.autoPlay=='true')}
+ if(flashVars.loop){loop=(flashVars.loop=='true')}
+ if(flashVars.volume){vol=Number(flashVars.volume)}
+ if(flashVars.balance){pan=Number(flashVars.balance)}
+ }
- private function setSource(src:String):void {
- pause();
- snd = new Sound(new URLRequest(src));
- if(autoPlay) play();
- }
+ import mx.controls.Alert;
+ private function initSound():void {
+ snd = new Sound(new URLRequest(source));
+ sndTr = new SoundTransform(vol, pan);
- private function play():void {
- if (!playing) {
- try{sndCh = snd.play(playResumePosition, 0, sndTr);}
- catch(err:Error){Alert.show(err.message,'Error');}
- sndCh.addEventListener(Event.SOUND_COMPLETE, sndCompleteHandler);
- playing = true;
- }
- }
+ snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
+ snd.addEventListener(ProgressEvent.PROGRESS, progressHandler);
+ snd.addEventListener(Event.COMPLETE, completeHandler);
- private function pause():void {
- if (playing) {
- playResumePosition = sndCh.position;
- sndCh.stop();
- playing = false;
- }
- }
+ if(autoPlay) play();
+ }
- private function playPause():void {
- if (playing) pause(); else play();
+ import flash.events.KeyboardEvent;
+ private function keyDnHnd(e:KeyboardEvent):void {
+ switch(e.keyCode) {
+ case 32: //space bar
+ playPause();
+ break;
+ case 36: //home
+ pause();
+ playResumePosition=(0);
+ break;
+ case 35: //end
+ if(playProgress.indeterminate) break;
+ pause();
+ playResumePosition=(snd.length);
+ break;
+ case 37: //<--
+ if(e.ctrlKey){
+ pan=Math.max(-1,pan-0.025);
+ balance(pan);
+ break;
}
-
- private function seek(p:Number):void {
- playResumePosition = p*1000;
- if (playing) {
- sndCh.stop();
- playing = false;
- play();
- }
+ if(!keyPressed){
+ deltaSeek=Math.max(100,snd.length/10000);
+ if(playing)
+ currentTime=sndCh.position;
+ else
+ currentTime=playResumePosition;
}
-
- private function rewind():void {
- seek(0);
+ keyPressed=true;
+ playResumePosition=Math.max(0,currentTime-deltaSeek);
+ if(playing) seek(playResumePosition/1000);
+ deltaSeek*=1.1;
+ break;
+ case 39: //-->
+ if(e.ctrlKey){
+ pan=Math.min(1,pan+0.025);
+ balance(pan);
+ break;
}
-
- private function volume(v:Number):void {
- sndTr.volume = v;
- if (playing) {
- pause();
- play();
- }
+ if(!keyPressed){
+ deltaSeek=Math.max(100,snd.length/10000);
+ if(playing)
+ currentTime=sndCh.position;
+ else
+ currentTime=playResumePosition;
}
-
- private function mute():void {
- if(muted) {
- if (lastVol==0) lastVol=0.75;
- volume(lastVol);
- muted=false;
- }
- else {
- lastVol = sndTr.volume
- volume(0);
- muted=true;
- }
+ keyPressed=true;
+ playResumePosition=Math.min(snd.length-10,currentTime+deltaSeek);
+ seek(playResumePosition/1000);
+ deltaSeek*=1.1;
+ break;
+ case 38:
+ vol=Math.min(1,vol+0.025);
+ volume(vol);
+ break;
+ case 40:
+ if(e.ctrlKey){
+ pan=0;
+ balance(pan);
+ break;
}
+ vol=Math.max(0,vol-0.025);
+ volume(vol);
+ break;
+ default:
+ if(e.charCode==109) mute(); //`m'
+ }
+ }
- private function initCallBacks():void {
- ExternalInterface.addCallback("play", play);
- ExternalInterface.addCallback("pause", pause);
- ExternalInterface.addCallback("playPause", playPause);
- ExternalInterface.addCallback("seek", seek);
- ExternalInterface.addCallback("rewind", rewind);
- ExternalInterface.addCallback("volume", volume);
- ExternalInterface.addCallback("mute", mute);
- ExternalInterface.addCallback("setSource", setSource);
- }
+ private function keyUpHnd(e:KeyboardEvent):void {
+ switch(e.keyCode) {
+ case 37: //<--
+ case 39: //-->
+ deltaSeek=Math.max(100,snd.length/10000);
+ keyPressed=false;
+ break;
+ }
+ }
- private function sndCompleteHandler(event:Event):void {
- playing = false;
- playResumePosition = 0;
- if(loop) play();
- }
+ private function formatTime(s:Number):String {
+ s/=1000;
+ var hrs:Number = Math.floor(s / 3600);
+ var min:Number = Math.floor(s / 60 % 60);
+ var sec:Number = Math.floor(s % 60);
- private function completeHandler(event:Event):void {
- playProgress.indeterminate=false;
- }
+ var fmtd:String='';
- import flash.events.ProgressEvent;
- private function progressHandler(event:ProgressEvent):void {
- playProgress.indeterminate=true;
- if(playing) {
- playProgress.setProgress(0.5,1);
- }
- }
+ if(hrs>0) fmtd = String(hrs)+':';
- private function onEnterFrame(event:Event):void {
- if(playProgress.indeterminate==false && playing) {
- playProgress.setProgress(sndCh.position,snd.length);
- }
- }
+ if(hrs>0 && min <10) fmtd+='0';
+ fmtd += String(min)+':';
- import flash.events.IOErrorEvent;
- private function errorHandler(errorEvent:IOErrorEvent):void {
- Alert.show(errorEvent.text + '\ncould not be loaded','Error');
- }
- ]]>
- </fx:Script>
+ if(sec<10) fmtd+='0';
+ fmtd += String(sec);
+
+ return fmtd;
+ }
+
+ private function addeventlisteners():void {
+ this.setFocus();
+ this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
+ this.addEventListener(KeyboardEvent.KEY_DOWN, keyDnHnd);
+ this.addEventListener(KeyboardEvent.KEY_UP, keyUpHnd);
+ }
+
+ private function setSource(src:String):void {
+ pause();
+ snd = new Sound(new URLRequest(src));
+ if(autoPlay) play();
+ }
+
+ private function play():void {
+ if(playing) return;
+ try{sndCh = snd.play(playResumePosition, 0, sndTr);}
+ catch(err:Error){Alert.show(err.message,'Error');}
+ sndCh.addEventListener(Event.SOUND_COMPLETE, sndCompleteHandler);
+ playing = true;
+ }
+
+ private function pause():void {
+ if(!playing) return;
+ playResumePosition = sndCh.position;
+ sndCh.stop();
+ playing = false;
+ }
+
+ private function playPause():void {
+ if(playing) pause(); else play();
+ }
+
+ private function seek(p:Number):void {
+ playResumePosition = p*1000;
+ if(!playing) return;
+ sndCh.stop();
+ playing = false;
+ play();
+ }
+
+ private function rewind():void {
+ seek(0);
+ }
+
+ private function volume(v:Number):void {
+ sndTr.volume = v;
+ sndCh.soundTransform=sndTr;
+ }
+
+ private function mute():void {
+ if(muted) {
+ if(lastVol==0) lastVol=0.75;
+ volume(lastVol);
+ muted=false;
+ }
+ else {
+ lastVol = sndTr.volume
+ volume(0);
+ muted=true;
+ }
+ }
+
+ private function balance(p:Number):void {
+ sndTr.pan = p;
+ sndCh.soundTransform=sndTr;
+ }
+
+ private function initCallBacks():void {
+ ExternalInterface.addCallback("play", play);
+ ExternalInterface.addCallback("pause", pause);
+ ExternalInterface.addCallback("playPause", playPause);
+ ExternalInterface.addCallback("seek", seek);
+ ExternalInterface.addCallback("rewind", rewind);
+ ExternalInterface.addCallback("volume", volume);
+ ExternalInterface.addCallback("balance", balance);
+ ExternalInterface.addCallback("mute", mute);
+ ExternalInterface.addCallback("setSource", setSource);
+ }
+
+ private function sndCompleteHandler(event:Event):void {
+ playing = false;
+ playResumePosition = 0;
+ if(loop) play();
+ }
+
+ private function completeHandler(event:Event):void {
+ playProgress.indeterminate=false;
+ }
+
+ import flash.events.ProgressEvent;
+ private function progressHandler(event:ProgressEvent):void {
+ playProgress.indeterminate=true;
+ }
+
+ private function onEnterFrame(event:Event):void {
+ if(!playProgress.indeterminate) {
+ if(playing) {
+ playProgress.setProgress(sndCh.position,snd.length);
+ playProgress.label=formatTime(sndCh.position);
+ } else {
+ playProgress.setProgress(playResumePosition,snd.length);
+ playProgress.label=formatTime(playResumePosition);
+ }
+ }else{
+ if(playing) {
+ playProgress.setProgress(Math.random(),1);
+ playProgress.label=formatTime(sndCh.position);
+ } else {
+ playProgress.setProgress(snd.bytesLoaded,snd.bytesTotal);
+ playProgress.label=formatTime(playResumePosition);
+ }
+ }
+ }
+
+ import flash.events.IOErrorEvent;
+ private function errorHandler(errorEvent:IOErrorEvent):void {
+ Alert.show(errorEvent.text + '\ncould not be loaded','Error');
+ }
+ ]]>
+ </fx:Script>
- <mx:ProgressBar width="100%" mode="manual"
- horizontalCenter="0" verticalCenter="0" labelPlacement="center"
- label="" id="playProgress"
- />
+ <mx:ProgressBar width="100%" mode="manual"
+ horizontalCenter="0" verticalCenter="0" labelPlacement="center"
+ label="" id="playProgress"
+ />
</s:Application>