From QB64 Wiki
- _SNDPLAYCOPY handle&[, volume!]
- The LONG handle& value is returned by _SNDOPEN using a specific sound file.
- The volume parameter can be any SINGLE value from 0 (no volume) to 1 (full volume).
- Opened sound files must have the "SYNC" capability to use this statement. (Currently WAV, OGG, AIF, RIF and VOC)
- Makes coding easier by doing all of the following automatically:
- Copies/duplicates the source handle (see [[_SNDCOPY}]]
- Changes the volume of the copy if volume is passed (file must have "VOL" capability)
- Plays the copy
- Closes the copy
- This statement is a better choice than _SNDPLAYFILE if the sound will be played often, reducing the burden on computer.
QB64 supports the following sound file formats (Bold is a guaranteed capability): WAV = "VOL,SYNC,LEN,PAUSE" Free WAV to OGG GUI converter OGG = "VOL,SYNC,LEN,PAUSE" Free WAV to OGG converter AIF = "VOL,SYNC,LEN,PAUSE" RIF = "VOL,SYNC,LEN,PAUSE" VOC = "VOL,SYNC,LEN,PAUSE" MID = "VOL" MOD = "VOL,PAUSE" MP3 = "VOL,PAUSE,SETPOS" Free WMA, MP3 and OGG converter Note: _SNDBAL only affects MP3 volume. Sound will reside in main channel.
Example 1: Playing a sound at half volume.
_SNDPLAYCOPY applause&, 0.5
Example 2: Playing a song at random volumes.
chomp& = _SNDOPEN("chomp.wav", "VOL,SYNC") _SNDPLAYCOPY chomp&, 0.5 + RND * 0.49