GoogleVR handling Close button in Stereo mode

Hello,

I’m trying to intercept the GoogleVR close button press so I can switch back to Mono. I’ve created the class below to attempt to catch the BackButtonPressed flag. However it doesn’t appear to ever change before the entire app is shutdown. Is BackButtonPressed the correct way to catch the press of this button?

Specs:

  • GVR SDK: GoogleVR 1.3.0
  • Unity: Unity 5.6f3
  • Phone: Google Nexus 5X, OS 7.1.2

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class VideoPlayerControls : MonoBehaviour
{
...
    /**
	 * Handle Cardboard back button press
	 */
	void Update ()
	{
		if (GvrViewer.Instance.BackButtonPressed)
		{
			print("BACK BUTTON PRESSED"); //This never gets displayed in Android logs

			// Handle Switch to Mono - This will call VRSettings.LoadDeviceByName("None");
			playlist.videos [0].cardboardMode = !playlist.videos [0].cardboardMode;
			player = PlayerFactory.Init (playlist, aControlType); 
			player.SetUrl (playlist.videos [0].url);
		}
	}
...

}

HI,

GvrViewer.Instance.BackButtonPressed, is indeed the way to check if is pressed.

Have you tried the below to toggle VR on/off?

GvrViewer.Instance.VRModeEnabled = !GvrViewer.Instance.VRModeEnabled;

I upgraded to GVR 1.6 and Unity 5.6.2f1 and removed all GvrViewer references. I’m able to detect the button press by checking for the ESC key.

/**
 * Handle Cardboard back button press
 */
void Update ()
{
	if (Input.GetKey(KeyCode.Escape))
	{
		print("CARDBOARD CLOSE BUTTON PRESSED");
		playlist.videos [0].cardboardMode = false;
		player = PlayerFactory.Init (playlist, aControlType);
		player.SetUrl (playlist.videos [0].url);
	}
}