1. Use the Sound class in Flash to control sound playback. The Sound class can directly load external MP3 files. Use the Sound.load(req) method of the Sound class. The parameter "req" is a The URLRequest variable stores the path name of the MP3 file.
2. The Sound class starts playing music after calling the Sound.play() method.
3. The Sound.play() method returns a variable of the SoundChannel class and assigns a value to this variable. Given an instance of the SoundChannel class, you can use the instance to control the pause of the music played by Sound, monitor the playback status, etc.
4. The SoundChannel class has a soundTransform property, whose value is an instance of the SoundTransform class. Assign a SoundTransform variable to the SoundChannel.soundTransform property, and you can use this variable to control the volume and left and right channels of the music.
5. If you need to draw a waveform graph, you must also use the SoundMixer class. Since it is not necessary, I won’t go into details.
6. Sound, SoundChannel, SoundTransform, and SoundMixer. These four classes are the four classes that must be used to make a music player. They are also the four classes most commonly used to control sounds in Flash.
Give an example to illustrate usage (note that the code cannot run normally directly)
var mySound: Sound;
//The path of MP3, The 1.mp3 file exists in the song folder under the Flash document directory
var req: URLRequest = new URLRequest( "song/1.mp3";);
var myChannel: SoundChannel = new SoundChannel();
var myTrans: SoundTransform = new SoundTransform();
mySound = new Sound();
mySound.load(req) ;
myChannel = mySound.play(); //Start playing music
trace(myChannel.position); //SoundChannel.position records the current playback position in milliseconds
p>myChannel.stop(); //Stop playing
myChannel = mySound.play(); //Start playing again from the beginning
myTrans = new SoundTransform(0) ; //Reinitialize myTrans, parameter 0 means mute
myChannel.soundTransform = myTrans; //Executing this line of code will mute the sound
myTrans = new SoundTransform(0); // Reinitialize myTrans, parameter 1 indicates the maximum volume
myChannel.soundTransform = myTrans; //Executing this code will maximize the volume