Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var url:String = "";
- var soundFactory:Sound;
- var channel:SoundChannel;
- var oldChannel:SoundChannel;
- var channelStack:Array = new Array();
- var vvolume:Number = 1;
- var positionTimer:Timer;
- var isMusicPlaying = false;
- var startPosition:Number = 0;
- playpausebtn.addEventListener(MouseEvent.CLICK, togglePlayback);
- stopbtn.addEventListener(MouseEvent.CLICK, stopPlayback);
- volup.addEventListener(MouseEvent.CLICK, mup);
- voldown.addEventListener(MouseEvent.CLICK, mdn);
- openbtn.addEventListener(MouseEvent.CLICK, oopf);
- function oopf(e:Event):void
- {
- isMusicPlaying = false;
- url = uuurl.text.substring(0, uuurl.text.length-1);
- SoundChannelExample();
- }
- function mup(e:Event):void
- {
- if(isMusicPlaying){
- vvolume+=0.1;
- var trans:SoundTransform;
- trans = new SoundTransform(vvolume, 0);
- channel.stop();
- startPosition = channel.position;
- channel = soundFactory.play(startPosition,1,trans);
- }
- }
- function mdn(e:Event):void
- {
- if(vvolume >= 0.1 && isMusicPlaying){
- vvolume-=0.1;
- var trans:SoundTransform;
- trans = new SoundTransform(vvolume, 0);
- channel.stop();
- startPosition = channel.position;
- channel = soundFactory.play(startPosition,1,trans);
- }
- }
- function stopPlayback(e:Event):void
- {
- channel.stop();
- channel = soundFactory.play(0);
- startPosition = channel.position;
- isMusicPlaying = false;
- channel.stop();
- //trace(channelStack.length);
- if(channelStack.length > 0) {channel = channelStack.pop(); startPosition = channel.position; isMusicPlaying = true;}
- }
- function togglePlayback(e:Event):void
- {
- if (isMusicPlaying)
- {
- startPosition = channel.position;
- channel.stop();
- isMusicPlaying = false;
- }
- else
- {
- channel = soundFactory.play(startPosition);
- isMusicPlaying = true;
- }
- }
- function SoundChannelExample() {
- var request:URLRequest = new URLRequest(url);
- soundFactory = new Sound();
- soundFactory.addEventListener(Event.COMPLETE, completeHandler);
- soundFactory.addEventListener(Event.ID3, id3Handler);
- soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
- soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
- soundFactory.load(request);
- if (channel!=null && !ovcheck.selected) channel.stop();
- else if(ovcheck.selected) channelStack.push(channel);
- channel = soundFactory.play();
- channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
- channel.stop();
- positionTimer = new Timer(50);
- positionTimer.addEventListener(TimerEvent.TIMER, positionTimerHandler);
- positionTimer.start();
- }
- function positionTimerHandler(event:TimerEvent):void {
- //trace("positionTimerHandler: " + channel.position.toFixed(2) + " VOL: " + channel.soundTransform.volume);
- timeStamp.text = "Progress: " + (channel.position / soundFactory.length*100).toFixed(2) + "% ~ "
- +(channel.position/1000).toFixed(0) + " / " + (soundFactory.length/1000).toFixed(0) + " sec."
- + " VOL: " + channel.soundTransform.volume;
- }
- function completeHandler(event:Event):void {
- //trace("completeHandler: " + event);
- }
- function id3Handler(event:Event):void {
- //trace("id3Handler: " + event);
- }
- function ioErrorHandler(event:Event):void {
- trace("ioErrorHandler: " + event);
- positionTimer.stop();
- }
- function progressHandler(event:ProgressEvent):void {
- //trace("progressHandler: " + event);
- }
- function soundCompleteHandler(event:Event):void {
- trace("soundCompleteHandler: " + event);
- positionTimer.stop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement