/// <summary> /// Class constructor. /// </summary> public CachedSoundProvider(CachedSound sound, long position) { _sound = sound; if (position < _sound.AudioData.Length) { _position = position; } }
/// <summary> /// Returns current position in specified looping sound, or 0 if not looping sound. /// </summary> public long GetLoopPosition(CachedSound sound) { long position = 0; lock (_loops) { CachedSoundProvider provider = _loops .Where(p => p.Sound == sound) .FirstOrDefault(); if (provider != null) { position = provider.Position; } } return(position); }
/// <summary> /// Plays a cached sound, looping forever until stop. Keeps playing if already looping specified sound. /// </summary> public void PlayLoop(CachedSound sound, bool stopOtherLoops = true, long position = 0) { CachedSoundProvider provider; lock (_loops) { if (stopOtherLoops) { _loops.Where(p => p.Sound != sound).ToList().ForEach(p => StopLoop(p.Sound)); } if (_loops.Where(p => p.Sound == sound).Any()) { return; } provider = new CachedSoundProvider(sound, position); _loops.Add(provider); } AddMixerInput(provider); }
/// <summary> /// Class constructor. /// </summary> public CachedSoundProvider(CachedSound sound) { _sound = sound; }
/// <summary> /// Plays a cached sound. /// </summary> public void PlaySound(CachedSound sound) { AddMixerInput(new CachedSoundProvider(sound)); }