# Progress bar with xml audio player

**URL:** https://forum.kirupa.com/t/progress-bar-with-xml-audio-player/297462
**Category:** flash
**Created:** [October 2, 2009, 12:57pm UTC](https://forum.kirupa.com/t/progress-bar-with-xml-audio-player/297462 "2009-10-02T12:57:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![L3EOO](https://avatars.discourse-cdn.com/v4/letter/l/d07c76/32.png) [@L3EOO](https://forum.kirupa.com/u/L3EOO)
#### Post date: [October 2, 2009, 12:57pm UTC](https://forum.kirupa.com/t/progress-bar-with-xml-audio-player/297462/1 "2009-10-02T12:57:41Z")

</div>

I am trying to create a XML based music player with a progress bar which shows the duration of the currently playing audio, the music player works fine, and although I got a version working in AS2 I cannot get the AS3 version right. I have a loop event in my play function which should be checking the duration played etc and altering the scaleX property of progressBar but something aint working at the mo, I am at a loss!

any help appreciated, my progress bar is called “progressBar”

here is my code::

var jukeboxX:XML;  
var songList:XMLList;  
var currentIndex:Number = 0;  
var currentSound:Sound;  
progressBar.scaleX = 0;

var firstSong:Sound = new Sound();  
var sc:SoundChannel;  
currentSound = firstSong;

var loader:URLLoader = new URLLoader();  
loader.addEventListener(Event.COMPLETE, onComplete);  
loader.load(new URLRequest(“songs.xml”));

function onComplete(e:Event):void  
{  
jukeboxX = new XML(loader.data);  
songList = jukeboxX.song;  
//trace(songList);

```
firstSong.load(new URLRequest(songList[currentIndex].url));
sc = firstSong.play();
title_txt.text = songList[currentIndex].author;
quote_txt.text = songList[currentIndex].title;

stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
next_btn.addEventListener(MouseEvent.CLICK, nextSound);
prev_btn.addEventListener(MouseEvent.CLICK, prevSound);

```

}  
function stopSound(e:Event):void  
{  
sc.stop();  
play\_btn.addEventListener(MouseEvent.CLICK, playSound);

}  
function playSound(e:Event):void  
{  
function loop(event:Event):void  
{  
var currentPosition:Number = sc.position / currentSound.length ;  
progressBar.scaleX = currentPosition;  
}  
sc.stop();  
sc = currentSound.play();  
play\_btn.removeEventListener(MouseEvent.CLICK, playSound);

}  
function nextSound(e:Event):void  
{  
var nextSound:Sound = new Sound();  
sc.stop();  
currentSound = nextSound;  
if (currentIndex \< songList.length() - 1)  
{  
currentIndex++;  
}  
else  
{  
currentIndex = 0;  
}  
nextSound.load(new URLRequest(songList[currentIndex].url));  
sc = nextSound.play();  
title\_txt.text = songList[currentIndex].author;  
quote\_txt.text = songList[currentIndex].title;

}  
function prevSound(e:Event):void  
{  
var prevSound:Sound = new Sound();  
sc.stop();  
currentSound = prevSound;  
if (currentIndex \> 0)  
{  
currentIndex–;  
}  
else  
{  
currentIndex = songList.length() - 1;  
}  
prevSound.load(new URLRequest(songList[currentIndex].url));  
sc = prevSound.play();  
title\_txt.text = songList[currentIndex].author;  
quote\_txt.text = songList[currentIndex].title;  
}
