rendered paste bodypackage audioplayer
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.text.*;
public class SoundApp extends MovieClip
{
private var pXMLLoader:XMLLoader;
private var pUIBar:UIBar;
private var pSongList:Array;
private var pSongIndex:int;
private var pSongState:int;
private var pSongPosition:int;
private var pPausePosition:Number;
private var pSound:Sound;
private var pSoundChannel:SoundChannel;
private var pSongInfo:SongInfo;
public function SoundApp()
{
trace("constructing SoundApp");
pSongInfo = new SongInfo();
pSongList = new Array();
pSongIndex = -1;
pSongState = SoundState.STOP;
pSongPosition = 0;
postCon();
}
public function postCon()
{
pUIBar = new UIBar(this);
pXMLLoader = new XMLLoader("xmldata/playlist.xml", this);
}
public function addSong(aSong:Song):void
{
trace(aSong);
pSongList.push(aSong);
}
public function doNextPhase():void
{
trace("Doing next phase");
}
public function doComplete(anEvent:Event):void
{
pSongIndex = (pSongIndex + 1) % pSongList.length;
if (pSoundChannel != null)
pSoundChannel.stop();
pSound = new Sound();
pSound.load(new URLRequest(pSongList[pSongIndex].filename));
pSoundChannel = pSound.play();
pSoundChannel.addEventListener(Event.SOUND_COMPLETE, doComplete);
}
public function doRewindButton():void
{
pSongIndex = (pSongIndex - 1) % pSongList.length;
if (pSoundChannel != null)
pSoundChannel.stop();
pSound = new Sound();
trace(pSongList);
pSound.load(new URLRequest(pSongList[pSongIndex].filename));
pSoundChannel = pSound.play();
pSoundChannel.addEventListener(Event.SOUND_COMPLETE, doComplete);
pSongState = SoundState.PLAY;
}
public function doNextButton():void
{
pSongIndex = (pSongIndex + 1) % pSongList.length;
if (pSoundChannel != null)
pSoundChannel.stop();
pSound = new Sound();
trace(pSongList);
pSound.load(new URLRequest(pSongList[pSongIndex].filename));
pSoundChannel = pSound.play();
pSoundChannel.addEventListener(Event.SOUND_COMPLETE, doComplete);
pSongState = SoundState.PLAY;
}
public function doPauseButton():void
{
if (pSoundChannel != null)
{
pSongPosition = pSoundChannel.position;
pSoundChannel.stop();
pSongState = SoundState.PAUSE;
}
}
public function doStopButton():void
{
if (pSoundChannel != null)
pSoundChannel.stop();
pSongState = SoundState.STOP;
pSongPosition = 0;
}
public function doPlayButton():void
{
if (pSongState == SoundState.PAUSE)
{
pSound = new Sound();
pSound.load(new URLRequest(pSongList[pSongIndex].filename));
pSoundChannel = pSound.play(pSongPosition);
pSongState = SoundState.PLAY;
}
else if (pSongState == SoundState.STOP)
{
if (pSongIndex == -1)
pSongIndex = (pSongIndex + 1) % pSongList.length;
pSound = new Sound();
pSound.load(new URLRequest(pSongList[pSongIndex].filename));
pSoundChannel = pSound.play();
pSongPosition = 0;
pSongState = SoundState.PLAY;
}
}
}
}