public bool TogglePlay() { stateChangeQueue.DispatchSync(() => { if (isPlaying) { player.Stop(); engine.Stop(); isPlaying = false; SetSessionActive(false); } else { SetSessionActive(true); ScheduleLoop(); ScheduleLoop(); NSError error; if (!engine.StartAndReturnError(out error)) { Console.WriteLine(error.LocalizedDescription); } player.Play(); isPlaying = true; } }); return(isPlaying); }
private void initPlayer() { audioEngine = new AVAudioEngine(); NSError error = new NSError(); if (!AVAudioSession.SharedInstance().SetPreferredSampleRate(sampleRate, out error)) { throw new Exception("Error setting preffered sample rate for player: " + error); } AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord, AVAudioSessionCategoryOptions.InterruptSpokenAudioAndMixWithOthers); AVAudioSession.SharedInstance().SetActive(true); audioPlayer = new AVAudioPlayerNode(); setVolume(AVAudioSession.SharedInstance().OutputVolume); inputAudioFormat = new AVAudioFormat(AVAudioCommonFormat.PCMFloat32, sampleRate, (uint)channels, false); audioEngine.AttachNode(audioPlayer); audioEngine.Connect(audioPlayer, audioEngine.MainMixerNode, inputAudioFormat); audioEngine.Prepare(); if (!audioEngine.StartAndReturnError(out error)) { throw new Exception("Error starting playback audio engine: " + error); } audioPlayer.Play(); }
public void ContinuePlaying() { IsPaused = false; PlayerNode.Play(); }