Play Scheduled
What it does: Starts playing the sound after the given amount of time with additional buffer time to fetch the data from media and returns an AudioError (see Possible Errors), showing wheter and how playing the sound after the given amount of time failed.
- DOES_NOT_EXIST
- MISSING_WRAPPER
- MISSING_SOURCE
- MISSING_CLIP
How to call it:
SoundName
is thename
we have given the sound we want to play after the given amount of time which would be the 10 seconds we’ve definedDelay
is the time after which we want to start playing the soundChild
is theChildType
that we want to call this method on
string soundName = "SoundName";
double delay = 10d;
ChildType child = ChildType.PARENT;
AudioError err = am.PlayScheduled(soundName, delay, child);
if (err != AudioError.OK) {
Debug.Log("Playing sound called: " + soundName + " after " + delay.ToString("0.00") + " failed with error id: " + err);
}
else {
Debug.Log("Playing sound called: " + soundName + " after " + delay.ToString("0.00") + " seconds succesfull");
}
Alternatively you can call the methods with less paramters as some of them have default arguments.
string soundName = "SoundName";
double delay = 10d;
AudioError err = am.PlayScheduled(soundName, delay);
if (err != AudioError.OK) {
Debug.Log("Playing sound called: " + soundName + " after " + delay.ToString("0.00") + " failed with error id: " + err);
}
else {
Debug.Log("Playing sound called: " + soundName + " after " + delay.ToString("0.00") + " seconds succesfull");
}
When to use it: When you want to switch smoothly between sounds, because the method it is independent of the frame rate and gives the audio system enough time to prepare the playback of the sound to fetch it from media, where the opening and buffering takes a lot of time (streams) without causing sudden CPU spikes.
Remarks: See AudioSource.PlayScheduled
for more details on what play scheduled does.