/// <summary> /// Disposes the Listener /// </summary> public void Dispose() { if (Listener.Ptr == IntPtr.Zero) { return; } AudioLayer.ListenerDisable(Listener); AudioLayer.ListenerDestroy(Listener); }
/// <summary> /// Disposes the Listener /// </summary> public void Dispose() { if (Listener.Ptr == IntPtr.Zero) { return; } #if !STRIDE_PLATFORM_IOS AudioLayer.ListenerDisable(Listener); AudioLayer.ListenerDestroy(Listener); #endif }
private void ActivateAudioSession() { const double preferedAudioLatency = 0.005; // start the AudioSession var audioSession = AVAudioSession.SharedInstance(); AVAudioSession.Notifications.ObserveInterruption((sender, args) => { if (args.InterruptionType == AVAudioSessionInterruptionType.Began) { AudioLayer.ListenerDisable(DefaultListener.Listener); } else { AudioLayer.ListenerEnable(DefaultListener.Listener); } }); // set the audio category so that: playback/recording is possible, playback is mixed with background music, music is stopped when screen is locked var error = audioSession.SetCategory(AVAudioSessionCategory.SoloAmbient); if (error != null) { Logger.Warning($"Failed to set the audio category to 'Ambient'. [Error info: {error.UserInfo}]"); State = AudioEngineState.Invalidated; return; } // Reduce the buffer size for better latency response.. audioSession.SetPreferredIOBufferDuration(preferedAudioLatency, out error); if (error != null) { Logger.Warning($"Failed to set the audio IO buffer duration to '{preferedAudioLatency}'. [Error info: {error.UserInfo}]"); } // set the preferred sampling rate of the application if (AudioSampleRate != 0) { audioSession.SetPreferredSampleRate(AudioSampleRate, out error); Logger.Warning($"Failed to set the audio session preferred sampling rate to '{AudioSampleRate}'. [Error info: {error.UserInfo}]"); } // activate the sound for the application error = audioSession.SetActive(true); if (error != null) { Logger.Warning($"Failed to activate the audio session. [Error info: {error.UserInfo}]"); State = AudioEngineState.Invalidated; } }