Audio
Audio, while a form of multimedia, is a little more complicated to include in a qdex module compared to an image or video. qdex audio does not use a player, and instead relies on the developer to start/stop the sound from script.
Before manipulating the audio from script, you must include the file in your qdex module as a collapsed video. This ensures that the files is uploaded to the repository and available for your users.
<video src="resources/myAudioFile.mp3" style="collapsed" />
Example 1: Playing Audio
If you would like to simply play audio, you can call audio.play("resources/fileName") from script. This method does not allow the user to stop or manipulate the audio in any way; once it starts, it will continue to play until its duration, or until the module is closed.
In this example, the audio file is played each time a user presses a button.
<button content="Play"> <onClick> audio.play("resources/myAudioFile.mp3") </onClick> </button>
Example 2: Starting/Stopping Audio
To be able to stop a particular audio track after it has started, you must create a variable to hold the value of the audio playback. This variable can then be called using the audio.stop method.
In this example, two buttons are used to start and stop a song.
<stack orientation="horizontal"> <button content="Play"> <onClick> aVariable = audio.play("resources/songName.mp3") </onClick> </button> <button content="Stop"> <onClick> audio.stop(aVariable) </onClick> </button> </stack>
Note that each time the Play button is pressed, a new instance of the audio track will play. To keep multiple versions of the same track from playing, the Play button should be disabled after press. The Stop button can re-enable the Play button.
To stop all audio, remove the variable name from the stop function, i.e.
<button content = "Stop All"> <onClick> audio.stop() </onClick> </button>
Appropriate Use
Like other features in qdex, audio has the ability to quickly become irritating to your users. We recommend limiting the use of audio to a select few use cases: