I am attempting to rewind a VideoPlayer in Unity, also I am using the new VideoPlayer API and an mp4. I have tried setting the playback speed to a negative number, but it pauses. My current solution is, In my rewind button script:
Technically, “videoPlayer.time = 0;” will return the video to the start, but if you want to control how much to rewind, you can declare a speed variable and just deduct that from the current time of the video.
The following code worked for my project:
If by rewind you mean reset to time = 0 and replay the video, I have this in a few projects and it never failed. In your case you want to use the first public method here.
public void PlayCurrentVideoClip()
{
Assert.IsNotNull(videoPlayer.clip);
PlayVideoClip(videoPlayer.clip);
}
public void PlayVideoClip(VideoClip _vc) {
StartCoroutine(PlayVideoClipCoroutine(_vc));
}
IEnumerator PlayVideoClipCoroutine(VideoClip _vc) {
videoPlayerUI?.SetActive(true);
yield return new WaitForEndOfFrame(); // safely wait 1 frame for the UI to be active
SetVideoClip(_vc);
videoPlayer.enabled = true;
videoPlayer.frame = 0;
videoPlayer.Play();
videoPlayer.EnableAudioTrack(0, true);
OnPlay.Invoke();
}
The only downside is that you might see a bit of a glitch where the video panel disappears for a split second. Can be annoying but not the end of the world.