How to Rewind Video Player in Unity?

你离开我真会死。 提交于 2019-12-24 21:10:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!