Play a range within an audio asset

IntermediateProgrammer

You can have Xenko play only certain portions of an audio asset. This means, for example, that you can create multiple samples from a single audio asset by specifying different ranges in different SoundInstance objects.

Loop points

You can use the following properties, methods, and structures:

Property, method, or structureFunction
Sound.TotalLengthThe total length of the sound.
SoundInstance.SetRange(PlayRange))Sets the time range to play within the audio asset.
PlayRangeTime information, including the range's starting point and length.
SoundInstance.PositionGets the current play position as TimeSpan.

For example:

  1. //Assume sample length is 5 seconds.
  2. var length = mySound.TotalLength;
  3. var begin = TimeSpan.FromSeconds(2);
  4. var duration = TimeSpan.FromSeconds(2);
  5. mySoundInstance.SetRange(new PlayRange(begin, duration));

See also