问题
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:
void Update ()
{
if (rewind == true) {
VideoController.Backward2Seconds();
}
}
In my VideoController Script
public void Backward2Seconds() {
if (!IsPlaying) return;
videoPlayer.time = videoPlayer.time - 2;
}
Is there a better way? Because this is laggy.
回答1:
Unfortunately, I am afraid that your first try was the best one, and that it is just your platform that doesn't support it. It could work on other devices. According to the VideoPlayer doc:
Support for negative values is platform dependent
Since it seems that this solution doesn't work on your device, your workaround might be improved by taking in account the time that passed between each frame. Try the following:
In you RewindButton script
void Update ()
{
if (rewind == true) {
VideoController.Backward(Time.deltaTime);
}
}
In your VideoController Script
public float Speed;
public void Backward(float deltaTime)
{
if (!IsPlaying) return;
videoPlayer.time = videoPlayer.time - deltaTime*Speed;
}
This should allow you to control the speed of the rewind while having a more fluid effect
来源:https://stackoverflow.com/questions/47910927/how-to-rewind-video-player-in-unity