playSound method
Plays the given Sound.
sound
: The Sound object to play.channel
: The specific channel ID to play the sound on. If -1 (default), an available channel will be chosen automatically from all channels.loop
: Whether the sound should loop. Defaults tofalse
.loopStart
: The start time in samples for looping, ifloop
istrue
. Converted to seconds internally using the sound's sample rate. RequiresloopEnd
to also be set.loopEnd
: The end time in samples for looping, ifloop
istrue
. Converted to seconds internally using the sound's sample rate. RequiresloopStart
to also be set.
Returns the channel ID on which the sound is playing, or -1 if the sound could not be played (e.g., sound not ready, retrigger delay not met, or no free channels).
Implementation
int playSound(Sound sound, {int channel = -1, bool loop = false, double? loopStart, double? loopEnd}) {
var targetChannels = (channel == -1) ? _allChannels : [channel];
return playSoundOnTargetChannels(
sound,
targetChannels: targetChannels,
loop: loop,
loopStart: loopStart,
loopEnd: loopEnd,
);
}