Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

Transcript

In this add-on, you will program a music playlist that users can change!

To start, add music to your program. Click the stage, select the “sounds” tab and “choose sound from library.” Select the music loops category. Select a sound and click OK. Then, click the “choose sound from library” button again, and select another. Select as many tracks as you’d like to play in your program! Select each track and rename each track as a number, starting with the number 1.

Next, start playing one of the tracks when the flag is clicked. Select the scripts tab.

Drag out a “play sound until done” block. Above that, snap a when flag clicked block.

Click the green flag to test it. Great! But the music only plays once. It should keep playing.

To make the music keep playing, place a “forever” block around the “play sound until done” block. Test it out. Great! The music repeats over and over.

Next, make the tracks change. To change the music to the next track, you need to tell the program which track to play. Create a "music" variable. Select the data menu, and click "make a variable." Variables hold values, like numbers or words. In this example, the variable will hold the track number. Name the variable "music," and click OK.

Place the “music” block in the “play sound until done” block. Now, the program will play the sound with the name that is in the “music” variable. But right now the “music” variable is 0 and there is no track named 0!

Drag out a “set music to 0” block, and change its value to 1. Place the block just after the “when flag clicked” block. Click the green flag to test it. Great, it works!

Drag out a “change music by 1” block to try changing the track. Cool! When the current track finishes playing, the track changes. Snap a “when right arrow key pressed” block on top. To test it, click the flag and then press the right arrow key. Cool!

But the “music” variable will keep increasing forever, and you don’t have that many music tracks! To make the music variable stop increasing after playing all the tracks, add an “if then” block around the “change music by 1” block. Place a “less than” block inside the diamond-shaped space.

On the left side, place a “music” variable block. On the right side, this example has 4 tracks. Click the green flag to test it. Press the right arrow key multiple times.

Great! The “music” variable never goes beyond 3.

Next, program the left arrow to allow users to go backward through the tracks. Right click the “when right arrow key pressed” block stack, and select duplicate. Change the dropdown to say “left arrow key.” Change the green operator block to a “greater than” block.

On the left side, place a “music” variable block. On the right side, type 1. Type negative 1 in the “change music by” block. Click the flag to test the whole thing. Cool!

Pressing the right and left arrow keys changes the track.

But, there’s a bug in the program. The music should change *as soon as* the user presses the arrow key, not when the track finishes playing.

To fix the bug, place a “stop all sounds” block above the “change music by 1” blocks.

Test it out! Great, the music changes immediately when the arrow keys are pressed.

Last, make sure your users know that they can control the sound in the program! Click the “paint a new sprite” button. Use the text tool to type instructions, like “Use the arrow keys to change the music!” Now everyone will know how to use the playlist you created! Now, it’s your turn: Add several music tracks to your program. Program the sound to start when the flag is clicked. Allow the user to change tracks by pressing the arrow keys using “change by” and “stop all sounds” blocks.

Finally, paint a new sprite to show off the music playlist feature.

Scegli un’estensione
La playlist per la moda
Permettete all'utente di scegliere la musica da riprodurre durante il progetto.
Più modelle
Selezionate una seconda modella e permettete all'utente di passare tra le due scelte.
Aggiungi un suono
Aggiungi un suono da riprodurre ogni volta che l'utente fa clic sulla modella.
Dettagli di moda
Disegna un'altra funzione e fai reagire la tua modella quando si fa clic su questa funzione.
Come fare un'entrata
Programma la tua modella a ruotare sul palco.
Effetti Speciali
Create un effetto ogni volta che l'utente fa clic sul completo.
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Guarda il video di introduzione.
  2. Scorri verso il basso per visualizzare i componenti aggiuntivi scelti.
  3. Seleziona un componente aggiuntivo e inizia a creare!
  4. Scegli un altro componente aggiuntivo e continua a costruire.