Sound programming
Project 8. Flash Radio
In today's project we will create an Internet-based "radio" To tell the truth it's not absolutely real "broadcast radio" where all audience listens the same voice or music from any receiver. Our radio is rather randomly loading player that pick ups songs from Internet and play them with streaming approximately like Real Player is doing. We need to advice you that you need to have quite fast Internet connection or our example will be "hiccupping" exactly like other streaming sound programs on your computer. We will use in our radio only 30 seconds clip to confirm to the copyrights.- Create a new file and extend it's timeline up to 2 frames.
- In the first frame enter the following code to create a new Sound instance but stop before playing it.
s1 = new Sound(); stop();
- Add also a button with the code that will send the movie to the next "playing" frame
on(release) { nextFrame(); } -
At the second frame of the main timeline add the following code
stop(); this.radio(); function radio() { track = Math.round((Math.random() * 8))+1; s1.loadSound("http://flashcare.com/sound/" + track + ".mp3", true); tracknum = track; s1.start(); s1.onSoundComplete = radio; }At first we stop at this frame. Then we are calling function radio, which created by ourselves.This function is the "core" of our radio application. By using random() and round() Math object methods we generate a number of the track it will be the number from 1 to 8. We will use it to load one of 8 tracks we have on server.
The next step to load the music file. Instead of attachSound() method we use loadSound() method that has two arguments first is ULR and here we use this random number to write the name of one of our files which are in the sequence from "track1.mp3" to "track6.mp3" .
If you want you may refer to sound files on another server, but be careful about names. If you use the same technique adjust your randomization code to the number of your files.
tracknum = track; line make the dynamic text with the variable "tracknum" assigned to display number of the track currently playing
At last sound plays and .
When it's completed it calls the function "radio" again and it generates new name of the file and plays it and so on.
- Add the dynamic text with the variable "tracknum" to display the current sound number. Add the button which stops the sound and goes back to the first frame
- Test your movie. You will hear 30 seconds song fragments playing one by one.
If you wish you may add the slider to change the volume of the sound, button to skip the current song and anything that you may invent to improve the radio.