From fbe16bb3dd88589901634061a0433bd2099264f6 Mon Sep 17 00:00:00 2001 From: mjtalbot Date: Mon, 3 Jun 2024 10:29:41 +0000 Subject: [PATCH] only start/stop the audio engine if its been initialized simple things first. after some debugging on audio "ducking" it looks like we only start to kill audio after we initialize the audio engine. this first "fix" simply prevents us from initializing the audio engine if its not already been initialized. when going into the background/foreground. other than this, we initialize the audio engine when you first play an audio clip in `void AudioEvent::play()` this still leaves an issue lying around where after we have initialized the audio engine we will now "forever" duck audio when we go into the background/foreground. but at least you should be able to avoid this entirely if you never load a file with audio. Diffs= d4b3118e1 only start/stop the audio engine if its been initialized (#7335) Co-authored-by: Maxwell Talbot --- .rive_head | 2 +- Source/Renderer/rive_renderer_view.mm | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.rive_head b/.rive_head index 30ea12c2..440b3880 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -dde676085908d492af545660cbbb19ee0d10d91d +d4b3118e1930e8e60565938a7c266d092a1ed940 diff --git a/Source/Renderer/rive_renderer_view.mm b/Source/Renderer/rive_renderer_view.mm index 6872055c..c0dc1add 100644 --- a/Source/Renderer/rive_renderer_view.mm +++ b/Source/Renderer/rive_renderer_view.mm @@ -24,12 +24,20 @@ @implementation RiveRendererView - (void)didEnterBackground:(NSNotification*)notification { - rive::AudioEngine::RuntimeEngine()->stop(); + auto engine = rive::AudioEngine::RuntimeEngine(false); + if (engine != nil) + { + engine->stop(); + } } - (void)didEnterForeground:(NSNotification*)notification { - rive::AudioEngine::RuntimeEngine()->start(); + auto engine = rive::AudioEngine::RuntimeEngine(false); + if (engine != nil) + { + engine->start(); + } } - (instancetype)initWithCoder:(NSCoder*)decoder