Daydream rejection due to audio not stopping with home/back button

Hi,

I am using Unreal 4.15 with Wwise to target daydream application. Unfortunately, by pressing the home/back button of the daydream controller, the game is paused but the audio sounds are not… such that we can still hear the ambient sounds in the google VR store .

How can we handle this issue because the home/back button of the daydeam controller is not mapped to any event ?

I noticed this as well :frowning:

Best would be to post it as an issue here: https://github.com/googlevr-unreal/UnrealEngine/issues
as google developed the GoogleVR plugin and fix bugs for it there.

It seems to only happen if I am using the Wwise plugin…

Unfortunately the AkAmbientSound provided by Wwise does not behave exactly like the AAmbientSound provided by Unreal Engine when the home button is pressed.

I am having the same problem as Sky3, but I am not using the Wwise plugin.

I am using the function ApplicationHasenteredForegroundDelegate, and when I press the home button it successfully pauses the game, but it doesn’t pause the sound just like Sky3 experienced. I am not using Wwise though.

And, yes, cannot get the app published because of this issue.

Hi,
I am trying this option too right now.
I realized that this event can be bind for an applicationLifeCycle component or a Platform Game Instance reference

Did you add the component applicationLifeCycle to an actor that you placed in a Level ?

210368-audioproblem.png

This is what I put in my player pawn.

Using this the game pauses when I press the home button but the sound does not.

When I attach a game pause function to the thumbpad the entire game pauses, including the sound. So I don’t think it’s an issue related to my sound file or the way the sound file executes.

Well, that’s interesting. Guess what works in UE4 4.16 but not in UE4 Master Release as of a few weeks ago…

I can confirm that I am not having this problem in 4.16.2, with I Google VR plugin 1.3 GVR NDK v1.40.0 and with that configuration my code works as expected.

It is NOT working with a somewhat modified version of the engine (master release from a few weeks ago form github) and a slightly modified version of google vr plugin 1.5 GVR NDK v1.60.1

I think the new audio mixer came in with the 4.17 preview. Didn’t it?

Also, the code for the Google VR plugin just appears to reference the UE4 functions. I don’t see code where there are any references to starting, pausing, or stopping audio files. Wouldn’t the UE4 functions do that instead?

// Register callbacks for pause and resume
FCoreDelegates::ApplicationWillEnterBackgroundDelegate.AddRaw(this, &FGoogleVRController::ApplicationPauseDelegate);
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.AddRaw(this, &FGoogleVRController::ApplicationResumeDelegate);

https://github.com/googlevr-unreal/UnrealEngine/blob/release/Engine/Plugins/Runtime/GoogleVR/GoogleVRController/Source/GoogleVRController/Private/GoogleVRController.cpp#L174

Okay. I just now tested my code with 4.17 release version with Google VR plugin version 1.5 (GVR NDK v1.60.1).

I packaged and deployed the app with the new audio engine switch on, and the audio did not pause.

I then packaged and deployed the app with the new audio engine switched off, and the audio DID pause as expected.

I switched it on and off by editing the AndroidEngine.ini and WindowsEngine.ini files as listed here:

So I suppose this is a bug?

For now, it looks quite difficult to meet the google requirement to get the daydream label. As you may know, audio has to stop when returning to the daydream “store”/place.

My backup plan is to use ambient sound with Unreal Audio engine and keep wwise to mix all the others sounds but if there is a bug in unreal 4.17…

Regarding the code, you are pointing an old revision of the code on the release branch ( the ongoing branch is 4.16-googlevr but anyway these lines are basically the same

https://github.com/googlevr-unreal/UnrealEngine/blob/release/Engine/Plugins/Runtime/GoogleVR/GoogleVRController/Source/GoogleVRController/Private/GoogleVRController.cpp#L174

https://github.com/googlevr-unreal/UnrealEngine/blob/6ffbe30b34dffe410a1e2f0dbca1a6c5ca06fa86/Engine/Plugins/Runtime/GoogleVR/GoogleVRController/Source/GoogleVRController/Private/GoogleVRController.cpp#L220link text

I guess that L169 and L170 are mapping the system home/back button

Buttons[(int32)EControllerHand::Left][EGoogleVRControllerButton::System] = FGamepadKeyNames::FGamepadKeyNames::SpecialLeft;
Buttons[(int32)EControllerHand::Right][EGoogleVRControllerButton::System] = FGamepadKeyNames::FGamepadKeyNames::SpecialRight;

Hey guys,

I’m looking at this issue now with our android platform expert. I need to switch back to android to test and repro the issue myself but what looks like is supposed to happen is on app suspension, in AndroidEventManager.cpp, void FAppEventManager::PauseAudio() is called.

This then grabs the “main” audio device and calls Suspend(false) on it.

Suspend’s implementation is:

void FAudioDevice::Suspend(bool bGameTicking)
{
	HandlePause(bGameTicking, true);
}

The FAudioDevice::HandlePause function checks some state and pauses each individual source playing source.

Can you verify that this is correct and calling HandlePause in the audio device code when your app is suspended?

This code is identical between the old audio engine and the new audio mixer. There’s a bit of a difference at the end where the audio mixer pauses sources (and where the android platform sound sources pause).

I’m working right now on verifying that Pause in audio mixer is working in general.

Pause does work in audio mixer in general. I spoofed a test that uses the exact same code I saw in android event manager and it works in audio mixer.

Trying to get Android back and up and running locally to see if I can repro your issue. It could be that I am wrong in my assumption that daydream specifically is using the same event logic. 4.17 shipped with audio mixer without SuspendContext implemented and specifically not implemented for iOS and Android. A hotfix is going out with this implemented for iOS. It should be easy to also add support for android if this is indeed the issue.

Ok, I was able to grab a google daydream and cook a map with a looping sound and I was able to repro the pause issue.

I fixed the issue by adding the following code.

In AndroidEventManager.cpp, change the PauseAudio and ResumeAudio functions to:

void FAppEventManager::PauseAudio()
{
	bAudioPaused = true;
    
	FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice();
	if (AudioDevice)
	{
		if (AudioDevice->IsAudioMixerEnabled())
		{
			AudioDevice->SuspendContext();
		}
		else
		{
			AudioDevice->Suspend(false);
		}
	}
}


void FAppEventManager::ResumeAudio()
{
	bAudioPaused = false;
   
	FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice();
	if (AudioDevice)
	{
		if (AudioDevice->IsAudioMixerEnabled())
		{
			AudioDevice->ResumeContext();
		}
		else
		{
			AudioDevice->Suspend(true);
		}
	}
}

Then, in AudioMixerDevice.cpp, make sure the FMixerDevice::ResumeContext() and FMixerDevice::SuspendContext() forwards the command to the platform interface:

	void FMixerDevice::ResumeContext()
	{
		AudioMixerPlatform->ResumeContext();
	}

	void FMixerDevice::SuspendContext()
	{
		AudioMixerPlatform->SuspendContext();
	}

This forwards to the platform interface (the very thin platform dependent layer in audio mixer). Then, in AudioMixerPlatformAndroid.h/.cpp, implement these functions. There already was a stub implementation in there with a dumb comment. Add the following (or, really move it) up to the //~ Begin IAudioMixerPlatformInterface block.

		virtual void SuspendContext() override;
		virtual void ResumeContext() override;

Then delete the old stub implementation, and then do the following implementation

	static bool bSuspended = false;

	void FMixerPlatformAndroid::SuspendContext()
	{
		if (!bSuspended)
		{
			bSuspended = true;
			// set the player's state to paused
			SLresult result = (*SL_PlayerPlayInterface)->SetPlayState(SL_PlayerPlayInterface, SL_PLAYSTATE_PAUSED);
			check(SL_RESULT_SUCCESS == result);
		}
	}

	void FMixerPlatformAndroid::ResumeContext()
	{
		// set the player's state to paused
		if (bSuspended)
		{
			bSuspended = false;
			SLresult result = (*SL_PlayerPlayInterface)->SetPlayState(SL_PlayerPlayInterface, SL_PLAYSTATE_PLAYING);
			check(SL_RESULT_SUCCESS == result);
		}
	}

I just tested on google daydream with this change and it appears to have fixed the issue.

Let me know if this fixes it for you, I’ll try and get the change out with the next 4.17 hotfix.

I guess you used an ambient sound actor in your level.
Right now, my project is using Wwise and their derived AkAmbientSound actor. So I have to wait for the new release of their plugin in 4.17 to test your fix for this project…
I will still build a sample code +your fix with the latest release of UE4.17 to try this.

Hi Minus_Kelvin. I implemented your code and it works. Problem solved. Thank you for your quick and immediate action. I will now apply for the daydream badge, and hopefully this go around it will get approved. Have a great day. And, once again, thank you for all your hard work.

Thanks for letting me know it fixed your issue. We submitted this fix to 4.17 so it should make it out in 4.17.2 hotfix.

Yeah, not quite sure how wWise sets their stuff up as we don’t do support for their wWise plugin ourselves. My fix is only for the new audio mixer in native UE4 audio. It shouldn’t affect their stuff at all.

![alt text][1]

I tried to add an Application Lifecycle component straightly through an add component node like you done it.
And I also tried to add this component to my VRPawn to stop audio with wwise but it is not doing anything in 4.17.

The main issue appears to be that theDaydream Background Delegate put the game in pause… preventing any others method to be called at this time…as audio or game saved etc.