From 44fcb5ace87eccefb71e05bc3d946c70ce16004f Mon Sep 17 00:00:00 2001 From: rohithzmoi <166651631+rohithzmoi@users.noreply.github.com> Date: Tue, 3 Sep 2024 14:52:12 +0530 Subject: [PATCH] Update audioengine.cpp Signed-off-by: rohithzmoi <166651631+rohithzmoi@users.noreply.github.com> --- iOS_OnlyFIles/audioengine.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/iOS_OnlyFIles/audioengine.cpp b/iOS_OnlyFIles/audioengine.cpp index addbc16..2122350 100644 --- a/iOS_OnlyFIles/audioengine.cpp +++ b/iOS_OnlyFIles/audioengine.cpp @@ -1,6 +1,7 @@ /* Copyright (C) 2019-2021 Doug McLain Modified Copyright (C) 2024 Rohith Namboothiri + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -372,29 +373,39 @@ void AudioEngine::process_audio(int16_t *pcm, size_t s) void AudioEngine::handleStateChanged(QAudio::State newState) { + static bool isSessionActive = false; + switch (newState) { case QAudio::ActiveState: qDebug() << "AudioOut state active"; - setupAVAudioSession(); - - + if (!isSessionActive) { + setupAVAudioSession(); + isSessionActive = true; + } break; + case QAudio::SuspendedState: qDebug() << "AudioOut state suspended"; - //setupBackgroundAudio(); - + if (isSessionActive) { + deactivateAVAudioSession(); + isSessionActive = false; + } break; + case QAudio::IdleState: qDebug() << "AudioOut state idle"; - setupBackgroundAudio(); - + setupBackgroundAudio(); break; + case QAudio::StoppedState: qDebug() << "AudioOut state stopped"; - + if (isSessionActive) { + deactivateAVAudioSession(); + isSessionActive = false; + } break; + default: - break; } }