The MP3 file format is a format often used for music. Glue supports MP3 files for audio. Keep in mind that the MP3 file format may be subject to licensing restrictions so be sure to research the availability of this format before distributing a game.
How to play a MP3 in your game
To play an MP3 in your game:
- Create or select the screen that you want to have the song
- Expand the screen to see the Files item
- Drag+drop the MP3 file from the explorer into a Screen’s Files node. Alternatively you can right-click on the Files tree node and select “Add File”->”Existing File” and browse to the location of the MP3
The song will automatically play when the Screen starts up. The song will automatically stop playing when the Screen exits. You do not need write any code to play or stop the music.
If a Screen contains multiple audio files, then additional settings and logic are needed to select which song should be played.
For information on how to loop songs, see the MediaPlayer page.
Moving between Screens (Glue)
Songs added in Glue belong to a particular Screen. To have songs persist between Screen transitions, see this page.
Optionally Playing Songs
You can add multiple songs to your Screen if you would like to select which one to play in custom code. To do this:
- Create a Screen
- Add any number of .mp3 files to your Screen
- Set each of them to LoadedOnlyWhenReferenced. For more information on this property, see the LoadedOnlyWhenReferenced page.
- In custom code, play the song you would like to play. For example, if your song is called MySong, then add the following code:
// Notice the song name is identical to the file name without the extension.
// In other words Song1.mp3 is referenced as Song1
FlatRedBall.Audio.AudioManager.PlaySong(Song1, true, false);