Advanced Features
Automating Volume and Pan Slider
Playing a specific file in the playlist
You can add "fast forward" and "rewind" buttons to allow the user to fast forward and rewind a song while it is playing. This is how you would add these buttons:
1. Add 2 buttons on the same timeline that the SoundPlayer is on, one for FF and one for REW.
2. Give each button an instance name, for example, ff_btn and rew_btn and also give the soundPlayer an instance name, for example splayer.
3. Add the following ActionScript code on the same timeline:
ff_btn.onPress=function()
{
splayer.moveOn(100,2)
}
ff_btn.onRelease=function()
{
splayer.moveOff()
}
rew_btn.onPress=function()
{
splayer.moveOn(100,-2)
}
rew_btn.onRelease=function()
{
splayer.moveOff()
}
Automating Volume and Pan Slider
You can use this, for example, where you would like to create an automated fade out effect when the user clicks on a button. Here's how you would do this:
1. Create a button on the same timeline as the soundPlayer and give it an instance name, for example fadeSound_btn.
2. Add the following ActionScript code on the same timeline:
// arguments for fadeOut method are
// 0 - value of the volume at the end of fade
// 2000 - number of milliseconds that fade will last
// _root - object that contains callback method
// "onFadeOut" - callback method;
fadeSound_btn.onRelease=function()
{
splayer.fadeSound(0, 2000, _root, "onFadeOut")
}
// onFadeOut callback method will be called when fadeSound is finished
// we are also calling the doStop method which has exactly the same functionality as pressing the stop button
this.onFadeOut=function()
{
trace("fade finished")
splayer.doStop();
}
You can use the same principle using the panSound method to create a panoramic sound effect.
The following 4 methods are used for handling the playlist:
1. getPlayList() - Returns an array of objects with the following properties: path, display_txt, streaming, buffer
If, for example, you would like to trace the current display list, you would use the following ActionScript:
// the variable pl will be an array containing objects for each playlist entry
var pl=splayer.getPlayList();
// here we loop thru the object array and trace the display_txt property
for (var i=0; i<pl.length; i++)
{
trace(pl[i].display_txt);
}
2. moveFile(id, new_id) - Changes the position of the file in the playlist
Say, for example, the getPlayList method in the example above gives us the following output:
Song 1 Display Text
Song 2 Display Text
Song 3 Display Text
Song 4 Display Text
The following code:
splayer.moveFile(3,1);
will change playlist output to this:
Song 1 Display Text
Song 4 Display Text
Song 2 Display Text
Song 3 Display Text* where splayer is the instance name of the soundPlayer component.
The first file in the playlist has an id of 0, the second had an id of 1 etc.
3. removeFile(id) - Removes the file from the playlist.
4. getCurrent(id) - Returns the id of file that is currently playing in the playlist
Playing a specific file in the playlist
To play a specific file that is in the playlist, simply pass the id of that file to the doPlay method, for example:
splayer.doPlay(3);
This will start playing fourth file from the playlist directly.