private void OnLoopRestart(IntPtr arg) { if (_playingSounds.ContainsKey(_id)) { _resource.Play(_voice); } else { _voice.BufferEnd -= OnLoopRestart; ReuseVoice(_id, ref _voice); } }
public void ReceiveMessage(IMessage pMessage) { var m = (AudioMessage)pMessage; AudioResource resource = m.Resource; float volume = m.Volume; SourceVoice voice; switch (pMessage.Type) { case "Play": case "Loop": System.Diagnostics.Debug.Assert(!resource.Disposed, "Audio resource has been disposed"); GetVoice(resource, m.ID, pMessage.Type == "Loop", out voice); if (voice.Volume != volume) { voice.SetVolume(volume); Device.CommitChanges(); } resource.Play(voice); _playingSounds.Add(m.ID, voice); break; case "Stop": if (_playingSounds.ContainsKey(m.ID)) { voice = _playingSounds[m.ID]; voice.Stop(); voice.FlushSourceBuffers(); _playingSounds.Remove(m.ID); } break; case "Pause": if (_playingSounds.ContainsKey(m.ID)) { voice = _playingSounds[m.ID]; voice.Stop(); } break; case "Resume": if (_playingSounds.ContainsKey(m.ID)) { voice = _playingSounds[m.ID]; voice.Start(); } break; } }