MP3 file (.mp3)

Introduction

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.

Glue loads MP3 files as Song instances. For more information on working with the Song class, see the Song page.

How to play a MP3 in your game

To play an MP3 in your game:

  • 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.

Looping songs

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:

  1. Create a Screen
  2. Add any number of .mp3 files to your Screen
    MultipleSongsInScreen.PNG
  3. Set each of them to LoadedOnlyWhenReferenced. For more information on this property, see the LoadedOnlyWhenReferenced page.
    SongLoadedOnlyWhenReferenced.png
  4. In custom code, play the song you would like to play. For example, if your song is called MySong, then add the following code:

For more information on the AudioManager, see the AudioManager page.