Trying to use the Gear VR touchpad as a play/pause input
Hi,
I've been trying for a while now with little luck to set up a pause/play in my project. The idea is that I have a texture playing a 360 video (this bit works fine). I have a Media Player Ctrl script that handles playback and playback states (paused, playing, etc).
I then wish to use a second script to handle the input functions using a tap on the Gear VR's touchpad - which I am to understand counts as a 'mouse 0' type input. I've checked Fire1 uses mouse 0 as the positive button.
I'm not getting any errors on my script in Unity, but tapping the touchpad isn't affecting playback at all :(
I'm a bit out of my depth with C# right now as a newbie, but I've used the basis of another GUI script and I believe it's connecting correctly with the media player Ctrl script.
Any thoughts or suggestions?
Thanks in advance, Laurence
using UnityEngine;
using System.Collections;
using System;
namespace VRStandardAssets.Utils
{
public class MedaiPlayerSampleGUI : MonoBehaviour
{
public MediaPlayerCtrl scrMedia;
public VRInteractiveItem m_VRInteractiveItem;
public bool m_bFinish = false;
// Use this for initialization
void Start()
{
scrMedia.OnEnd += OnEnd;
}
// Update is called once per frame
void Update()
{
if (scrMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PLAYING)
{
if (Input.GetButtonDown("Fire1"))
{
scrMedia.Pause();
}
}
if (scrMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PAUSED)
{
if (Input.GetButtonDown("Fire1"))
{
scrMedia.Play();
}
}
}
void OnEnd()
{
m_bFinish = true;
}
}
}
So I believe I've managed to solve the problem of getting the Gear VR touchpad to update the Pause/Play status on the Video$$anonymous$$anager now. If it's of any interest to anyone, my solution was as follows:
using UnityEngine;
using VRStandardAssets.Utils;
namespace VRStandardAssets.Examples
{
// This script shows a simple example of how
// swipe controls can be handled.
public class VideoPausePlay : $$anonymous$$onoBehaviour
{
[SerializeField] private $$anonymous$$ediaPlayerCtrl scr$$anonymous$$edia;
private VRInput m_VRInput;
public VRInput OnClick;
void Update()
{
if (OnClick != null)
HandleOnClick();
}
//Handle the OnClick events deter$$anonymous$$ed by current state of playback in Video$$anonymous$$anager
void HandleOnClick()
{
if (scr$$anonymous$$edia.GetCurrentState() == $$anonymous$$ediaPlayerCtrl.$$anonymous$$EDIAPLAYER_STAT$$anonymous$$PLAYING)
scr$$anonymous$$edia.Pause();
else if (scr$$anonymous$$edia.GetCurrentState() == $$anonymous$$ediaPlayerCtrl.$$anonymous$$EDIAPLAYER_STAT$$anonymous$$PAUSED)
scr$$anonymous$$edia.Play();
}
}
}
The trouble I have now is that the state is changing without any input at all :/ It's progress of sorts I guess. I'll update if I crack it any time soon, but in the mean time, please do let me know if I'm making some glaringly obvious bumble!
Answer by laurencenairne · Feb 07, 2017 at 02:14 PM
By Jove, I've got it!
The trick is not to bother using VRInput for this, just use the regular Input.GetMouseButtonDown method.
Touchpad counts as mouse 0, so if the script is written like so:
using UnityEngine;
using VRStandardAssets.Utils;
namespace VRStandardAssets.Examples
{
public class VideoPausePlay : MonoBehaviour
{
[SerializeField] private MediaPlayerCtrl scrMedia;
void Update()
{
if (Input.GetMouseButtonDown(0))
if (scrMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PLAYING)
scrMedia.Pause();
else if (scrMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PAUSED)
scrMedia.Play();
}
}
}
This will Pause when the video is playing, or Play when the video is paused. In the Editor you will need to drag the gameObject that contains the MediaPlayerCtrl script onto the corresponding "Scr Media" field so it knows which Video Manager to look to for player status.