Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by laurencenairne · Feb 09, 2017 at 07:13 PM · scripting problemvrvideoplayback

Correct way to handle playback with swipe gestures

Hi there,

I'm hoping I can solve this myself, but on the off chance there's somebody out there with the free time and patience to assist, I'm trying to drive a video playback seek bar by VRInput Swipe direction.

The basic idea is that, rather than using drag inputs (as this doesn't work for Gear VR and cardboard) to update the position of the slider and therefore change the timestamp of the video, I'll instead use swipe direction to change the position of playback by a predefined float value (m_fSwipeValue).

I began with a basic SeekBarCtrl script which comes with the Easy Movie Texture asset package, and added my own elements to this. I'm not receiving any errors in Unity, but swipe events just aren't doing anything.

 using System;
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 using VRStandardAssets.Utils;
 
 
 #if !UNITY_WEBGL
 
 public class VRSeekBarCtrl : MonoBehaviour ,IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler{
 
     public VRInput m_VRInput;
 
 
     public MediaPlayerCtrl m_srcVideo;
     public Slider m_srcSlider;
     public float m_fDragTime = 0.2f;
     public float m_fSwipeValue = 0.05f;
 
 
     bool m_bActiveDrag = true;
     bool m_bUpdate = true;
 
     float m_fDeltaTime = 0.0f;
     float m_fLastValue = 0.0f;
     float m_fLastSetValue = 0.0f;
 
     // Use this for initialization
     void Start () {
 
     }
 
 
     // Update is called once per frame
     void Update () {
 
         if (m_bActiveDrag == false) {
             m_fDeltaTime += Time.deltaTime;
             if (m_fDeltaTime > m_fDragTime) {
                 m_bActiveDrag = true;
                 m_fDeltaTime = 0.0f;
                 //if(m_fLastSetValue != m_fLastValue)
                 //    m_srcVideo.SetSeekBarValue (m_fLastValue);
             }
         }
 
         if (m_bUpdate == false)
             return;
 
         if (m_srcVideo != null) {
 
             if (m_srcSlider != null) {
                 m_srcSlider.value = m_srcVideo.GetSeekBarValue();
 
             }
 
         }
 
         m_VRInput.DetectSwipe ();
     }
 
     public void OnPointerEnter(PointerEventData eventData)
     {
         Debug.Log("OnPointerEnter:");  
 
         m_bUpdate = false;
 
 
 
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log("OnPointerExit:");
 
         m_bUpdate = true;
 
 
     }
 
     public void OnPointerDown(PointerEventData eventData)
     {
 
 
     }
 
     public void OnPointerUp(PointerEventData eventData)
     {
 
         m_srcVideo.SetSeekBarValue (m_srcSlider.value);
 
 
 
 
 
 
     }
 
 
     public void OnDrag(PointerEventData eventData)
     {
         Debug.Log("OnDrag:"+ eventData);   
 
         if (m_bActiveDrag == false) 
         {
             m_fLastValue = m_srcSlider.value;
             return;
         }
 
         m_srcVideo.SetSeekBarValue (m_srcSlider.value);
         m_fLastSetValue = m_srcSlider.value;
         m_bActiveDrag = false;
     }
 
     public void DetectSwipe(){
     
         //mouse moves left
         if (m_VRInput.DetectSwipe() == VRInput.SwipeDirection.LEFT){
 
             m_srcSlider.value = m_fLastValue - m_fSwipeValue;
             m_srcVideo.SetSeekBarValue (m_srcSlider.value);
             m_fLastSetValue = m_srcSlider.value;
 
         }
 
         if (m_VRInput.DetectSwipe () == VRInput.SwipeDirection.RIGHT) {
 
             m_srcSlider.value = m_fLastValue + m_fSwipeValue;
             m_srcVideo.SetSeekBarValue (m_srcSlider.value);
             m_fLastSetValue = m_srcSlider.value;
 
         }
 
     }
 }
 #endif

And I expect I will get a response of 'learn the basics' first or 'read documentation', so just to clear that up, I've been referring to Google searches and documentation extensively for a couple days before posting this question, and unfortunately I'm the type of 'learn by doing' type of person, and there are no related walkthrough tutorials that I've found.

Thanks in advance :)

Laurence

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by laurencenairne · Feb 10, 2017 at 10:47 AM

I ended up referencing OVRTouchpad script to get it working instead of VRInput - it worked much better, though I realised my inputs were back to front some how, so swipe left was increasing playback position, right was decreasing. For any that find it useful:

 using System;
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 using VRStandardAssets.Utils;
 
 #if !UNITY_WEBGL
 
 public class VRSeekBarCtrl : MonoBehaviour ,IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler{
     
     public MediaPlayerCtrl m_srcVideo;
     public Slider m_srcSlider;
     public float m_fDragTime = 0.2f;
     public float m_fSwipeValue = 0.05f;
 
     bool m_bActiveDrag = true;
     bool m_bUpdate = true;
 
     float m_fDeltaTime = 0.0f;
     float m_fLastValue = 0.0f;
     float m_fLastSetValue = 0.0f;
 
     // Use this for initialization
     void Start () 
     {
         OVRTouchpad.Create ();
         OVRTouchpad.TouchHandler += HandleTouchHandler;
     }
         
     // Update is called once per frame
     void Update () {
 
         if (m_bActiveDrag == false) 
         {
             m_fDeltaTime += Time.deltaTime;
             if (m_fDeltaTime > m_fDragTime) 
             {
                 m_bActiveDrag = true;
                 m_fDeltaTime = 0.0f;
             }
         }
 
         if (m_bUpdate == false)
             return;
 
         if (m_srcVideo != null) {
 
             if (m_srcSlider != null) {
                 m_srcSlider.value = m_srcVideo.GetSeekBarValue();
             }
         }
     }
 
     public void OnPointerEnter(PointerEventData eventData)
     {
         Debug.Log("OnPointerEnter:");  
 
         m_bUpdate = false;
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log("OnPointerExit:");
 
         m_bUpdate = true;
     }
 
     public void OnPointerDown(PointerEventData eventData)
     {
 
     }
 
     public void OnPointerUp(PointerEventData eventData)
     {
         m_srcVideo.SetSeekBarValue (m_srcSlider.value);
     }
 
     public void OnDrag(PointerEventData eventData)
     {
         Debug.Log("OnDrag:"+ eventData);   
 
         if (m_bActiveDrag == false) 
         {
             m_fLastValue = m_srcSlider.value;
             return;
         }
 
         m_srcVideo.SetSeekBarValue (m_srcSlider.value);
         m_fLastSetValue = m_srcSlider.value;
         m_bActiveDrag = false;
     }
 
     void HandleTouchHandler(object sender, System.EventArgs e){
 
         OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e;
 
         //mouse moves left - skip backwards
         if (touchArgs.TouchType == OVRTouchpad.TouchEvent.Left)
         {
             m_srcSlider.value = m_fLastSetValue + m_fSwipeValue;
             m_srcVideo.SetSeekBarValue (m_srcSlider.value);
             m_fLastSetValue = m_srcSlider.value;
         }
 
         //mouse moves right - skip forwards
         if (touchArgs.TouchType == OVRTouchpad.TouchEvent.Right) 
         {
             m_srcSlider.value = m_fLastSetValue - m_fSwipeValue;
             m_srcVideo.SetSeekBarValue (m_srcSlider.value);
             m_fLastSetValue = m_srcSlider.value;
         }
     }
 }
 #endif

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Videoplayerprepare Problem 0 Answers

load scene after video ended 2 Answers

360 Video player not Synced with Audio 0 Answers

3D 360 Video Panoramic Skybox 1 Answer

Photon Networking: Moving all players vr 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges