# unity video player time as countdown

anyone knows how can i do video player time as countdown? it will start from length of video and countdown to zero. but it will be minutes and seconds. my script is this.

``````string minutes = Mathf.Floor((int)videoPlayer.time / 60).ToString("0");
string seconds = ((int)videoPlayer.time % 60).ToString("00");

currentVideoTime.text = minutes + ":" + seconds;
``````

this part only video player time

Invoke a function every second which gets the current time from the videoplayer

Invoke a function every second which gets the current time from the videoplayer
[/quote]I couldn’t do it. can you help me?

``````timeSinceLastCheck += Time.deltaTime;
if (timeSinceLastCheck > 1.0){
//do update
TimeSinceLastCheck = 0;
}
``````

I think it won’t work because I want to do this with video. there ise skipping, stop, play, pause everything. time.deltatime won’t work

Then

If (TimeLeft - totaltime > 1.0){
TimeLeft = video.timeLeft;
//do stuff
}

If it has a total time variable just use that minus what already played

but will it work on pause, skipping , stop etc? I tried this on my code but I couldn’t do it. this part is only looking forward

``````string minutes = Mathf.Floor((int)videoPlayer.time / 60).ToString("0");
string seconds = ((int)videoPlayer.time % 60).ToString("00");
currentVideoTime.text = minutes + ":" + seconds;
``````

Well .time gives you the time that already played, that’s half the equation, but for the total time i don’t see a variable in the video player API, maybe the clip has that property
but what you can do is figure it out by the current frame, total frames and FPS and see how lond is left

I wrote this one. but does not work again. when countdown to zero at 1 minute, turning minus and. so like this: 1:-01,1:-02 etc

``````string minutes = Mathf.Floor(-(int)videoPlayer.time / 60 + (int)videoPlayer.clip.length / 60).ToString("0");
string seconds = (-(int)videoPlayer.time % 60 +  (int)videoPlayer.clip.length % 60).ToString("00");

currentVideoTime.text = minutes + ":" + seconds;
``````