1

I'm facing a problem, please help me if it is possible.

I'm practicing unity and I'm trying to make sth for myself. And I'm playing a video using UI and canvas raw image and what I need is this:

I want to tell animator to start a special animation when the movie reaches a specific frame or time for example when it reaches at 10 seconds I want to make the movie stop and that animation be triggered.

I don't have any problem with playing or pausing my video or triggering animations in animators...

My problem is that I don't know how to get the number of current frame playing in movie using script

I tried using time functions to solve my problem but it has two disadvantages , first its not accurate !! each time it results in a small different out come and I don know exactly why , second it becomes hard if I change something else for example actions before that movie

In short my question is this: is there any way to get the current frame number of a movie using script in unity ? ( a movie which is playing using UI and canvas and raw image )

Thanks a lot in advance...

derHugo
  • 83,094
  • 9
  • 75
  • 115
JaamySK
  • 99
  • 1
  • 11

1 Answers1

3

Is there any way to get the current frame number of a movie using script in unity ?

Yes. You can obtain the current video frame with the VideoPlayer.frame variable.

Note that it works like an array index. 0 is the first frame and 1 is the second frame.


You seem to confuse video frame with video time in the title of this question. They are two different stuff.

You can obtain the video time with VideoPlayer.time. You just check when it is 10 seconds in the Update function then do something.

VideoPlayer vidPlayer = null;
void Update()
{
    if (vidPlayer.time == 10)
    {
        ///
    }
}

See here for how to play video with the VideoPlayer API.

Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328