Search Unity

Video Starting Video and Audio at a specific time

Discussion in 'Audio & Video' started by HeyBishop, Jul 1, 2017.

  1. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    In my scene I have several game objects that have a video player and audio source. All the game objects are playing the same looping video and audio content.

    How can I start each video and audio clip at a different time?

    Example:
    Screen01 starts at the beginning,
    Screen02 starts 30 seconds into the video,
    Screen03 starts at 60 seconds into the video,
    and so on.
     

    Attached Files:

    Last edited: Sep 14, 2017
    lritterhh likes this.
  2. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    Forgive me if it's uncouth to bump a thread in this forum... but I'm still stuck on this. I've tried everything I can think of.

    Does anyone have any insight into how one can start a video playing on a frame other than frame 0?
     
  3. lritterhh

    lritterhh

    Joined:
    Jul 26, 2017
    Posts:
    2
    Did you ever find a solution to this problem? I am stuck on this as well. I feel as if it should be simple but nothing has worked.
     
  4. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    @lritterhh, no I haven't.
    Here's my current code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class MyPlayVideo : MonoBehaviour {
    4.     private float t;
    5.     private GvrVideoPlayerTexture player;
    6.  
    7.     public float delay = 2f;
    8.     public long startFrame;
    9.  
    10.     void Start() {
    11.         t = 0;
    12.         player = GetComponent<GvrVideoPlayerTexture>();
    13.         player.Init();
    14.         player.Pause ();
    15.         player.CurrentPosition = startFrame;  // I've also tried this code in update
    16.     }
    17.  
    18.     void Update() {
    19.         if (player.PlayerState == GvrVideoPlayerTexture.VideoPlayerState.Ended)
    20.         {
    21.             player.Pause ();
    22.             player.CurrentPosition = 0;
    23.             t = 0f;
    24.             return;
    25.         }
    26.        
    27.       t += Time.deltaTime;
    28.       if (t >= delay)
    29.         {
    30. //        player.CurrentPosition = startFrame;  // it doesn't work here
    31.             player.Play ();
    32. //        player.CurrentPosition = startFrame;  // or here
    33.           }
    34.     }
    35. }
    This code successfully gets the video to play, after a delay. But it always starts on frame 0.

    I'm just about to give up on Daydream. If this isn't possible, I might have to consider a different platform/device.
     
  5. jocyf

    jocyf

    Joined:
    Jan 30, 2007
    Posts:
    288
    You need some kind of SetFrame() function in your VideoPlayer:

    Code (CSharp):
    1.  
    2. public void SetFrame(long nFrame){
    3.         nFrame = (long) Mathf.Clamp (nFrame, 0, video.clip.frameCount-1);
    4.         video.frame = nFrame;
    5. }
    6.  
    So you can replace the
    player.CurrentPosition = startFrame;
    by
    player.SetFrame( startFrame );


    I've haven't tested setting a frame in the video in months, so I can't confirm if it works in Unity v2017.3.1 (It didn't work fine a year ago).