Search Unity

Question Setting frame on video.loopPointReached event not working

Discussion in 'Audio & Video' started by Project-NSX, Mar 14, 2022.

  1. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    25
    Hi all
    I am trying to set a custom start frame for a video. This all works well just but on my video.loopPointReached event setting the frame to any number other than 0 causes the video to just pause on the end frame.
    In the start method I am subscribing to the event using:
    Code (CSharp):
    1. video.loopPointReached += EndReached;
    Then in the event I am trying to set the start frame using:
    Code (CSharp):
    1.     void EndReached(UnityEngine.Video.VideoPlayer vp)
    2.     {
    3.         video.Play();
    4.         video.frame = startFrame;
    5.     }
    As I mentioned, setting video.frame = 0; works as expected, but any number other than 0 doesn't.

    Does anyone have any idea about this?

    Thanks
     
  2. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    For the video player to play without pausing, it needs to decode frames continuously. When you jump to a frame, the video player doesn't have frames required to continue, so it pauses and starts waiting for new frames. Because of that, you can't simply do what you are doing (at least if you want a smooth transition). The best solution would be to cut the start of the video and use the looping feature on the VideoPlayer. If for other reasons, you can't do that, the workaround you could do is using 2 video players. One playing normally and the other waiting at the specific frames. When you get the loopPointReached event, you hide the current video player and show the one ready to play. While the new one is playing, you can then change the video frame to whatever you want.
     
  3. Project-NSX

    Project-NSX

    Joined:
    Apr 11, 2019
    Posts:
    25
    Ah I see, thanks!