MP3 : play, pause, stop
The purpose is to show how to use buttons Play, Pause, Stop while playing a MP3.
We'll use 'Streaming' because sound is played when downloading instead of event sounds which are entirely downloaded before being played.
This is a quite basic example.
Remarks :
- Sound object can't be tested with Swishmax, so we 'll use ActionScript methods. Thus, to test, select the correct option in Files / Export
- It'd be better to wait a couple of seconds before playing the sound to be sure streaming has begun.
I suppose you know well how to create objects then I won't insist on. Be sure to check out you got the correct Anchor Points and Target as well.
⇒ animation ⇐
You need to be patient a couple of seconds 'cause during Streaming, your Browser Cache is filling up and song is 2.4 MB large.
Let's see the different stages right now.
Création des Objets
1 - Set up movie size 200x60 (background #514F03). Any Frame Rate 'll fit.
2 - Import image barreSons.gif. Place it on the scene.
3 - You gonna create virtual buttons to simulate actions : play, pause, stop. You avoid to create many images.
4 - Draw a rectangle which surrounds Play zone as shown hereafter :
No borderline, no fiiling.
5 - Menu Modify / Convert / Convert to Button Name it : Play.
6 - Process in the same way for Pause et Stop.
Scripts
In Outline, select Scene_1. Enter the following script :onLoad ()
{
sonMP3 = new Sound(); // new sound object
// load son from current directory ( true = streaming)
sonMP3.loadSound( "machanson.mp3", true);
// Streaming : playing is automatic so let's stop it.
sonMP3.stop();
// init elapsed time to 0.
elapsed = 0;
}
In Outline, select Play. Enter the following script :
on (release)
{ // play sound at position stored in variable elapsed.
sonMP3.start(_root.elapsed);
}
In Outline, select Stop. Enter the following script :
on (release)
{
sonMP3.stop();
_root.elapsed = 0;
}
In Outline, select Pause. Enter the following script :
on (release)
{
sonMP3.stop();
_root.elapsed = sonMP3.position / 1000; // elapsed time.
}