Play a WAV file, stored on a SD card.
Port | Purpose |
---|---|
Out 0 | Left Channel Output |
Out 1 | Right Channel Output |
play(filename);
Begin playing a WAV file. If a file is already playing, it is stopped and this file starts playing from the beginning.
stop();
Stop playing. If not playing, this function has no effect.
isPlaying();
Return true (non-zero) if playing, or false (zero) when not playing. See the note below about delayed start.
positionMillis();
While playing, return the current time offset, in milliseconds. When not playing, the return from this function is undefined.
lengthMillis();
Return the total length of the current sound clip, in milliseconds. When not playing, the return from this function is undefined.
File > Examples > Audio > WavFilePlayer
Only 16 bit PCM, 44100 Hz WAV files are supported. When mono files are played, both output ports transmit a copy of the single sound. Of course, stereo WAV files play with the left channel on port 0 and the right channel on port 1.
A brief delay after calling play() will usually occur before isPlaying() returns true and positionMillis() returns valid time offset. WAV files have a header at the beginning of the file, which the audio library must read and parse before playing can begin.
While playing, the audio library accesses the SD card automatically. If card access is required, you must use AudioNoInterrupts() to prevent the library from accessing the SD card while you use it. Disabling the audio library interrupt for too long may cause audible dropouts or glitches.