Search code examples
unity-game-enginegoogle-cardboardvirtual-reality

Cardboard in Unity: Android volume controls not working in VR mode


If I play my game with the VR mode disabled, I can push on volume up and down of my smartphone. However, if the VR is enabled, the volume buttons of the smartphone don't work.

I have search the following words in my complete solution: VolumeLevel, AudioListener, volume, and KeyEvent.KEYCODE_VOLUME_DOWN. No result at all, so nowhere in any script seems to be changing or blocking those controls.

Why aren't the volume buttons working?


Solution

  • The Cardboard SDK disables the volume keys (on Android) when VR mode is active. This is because when the phone in a Cardboard viewer, it is easy for the user to accidentally toggle the volume keys since they are laying flush against the bottom of the viewer. A little extra pressure there and the volume key events start coming in. Since the volume bar that Android displays is not in stereo, it causes major eye strain when it pops up in your Cardboard view.

    BTW, if you tap the Settings gear at the bottom, so the app pops up the dialog asking if you want to configure your viewer, the volume keys are active at that point. You can adjust the volume, then hit Cancel to go back to your app.