home/ atoms/ of-sound-player-playback

ofSoundPlayer loads and plays a sound file from bin/data with load() then play()

openFrameworks handles audio file playback via the ofSoundPlayer class. The sound file must first be saved in the project’s bin/data folder. You declare an ofSoundPlayer, call load(filename) once (typically in setup()) to read the file, and call play() to trigger playback. setLoop(true) makes the sound repeat continuously. Supported formats include .wav and .mp3. This mirrors the ofImage pattern: an expensive load() up front, cheap trigger calls thereafter.

Examples

// ofApp.h: ofSoundPlayer mySound; // setup(): mySound.load(“beat.mp3”); mySound.setLoop(true); // keyPressed(): mySound.play();

Assessment

Write the declaration and the two calls needed to load and loop a WAV in bin/data; then state where the file must live and why load() belongs in setup().

“You simply initialize an ofSoundPlayer, load the sound file, and play the sound file.”