简体   繁体   English

如何在Unity中倒带Video Player?

[英]How to Rewind Video Player in Unity?

I am attempting to rewind a VideoPlayer in Unity, also I am using the new VideoPlayer API and an mp4. 我试图在Unity中倒带VideoPlayer,也正在使用新的VideoPlayer API和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 在我的VideoController脚本中

public void Backward2Seconds() {
    if (!IsPlaying) return;
        videoPlayer.time = videoPlayer.time - 2;
}

Is there a better way? 有没有更好的办法? Because this is laggy. 因为这很慢。

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 : 根据VideoPlayer文档

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 在您的RewindButton脚本中

void Update ()
{
    if (rewind == true) {
        VideoController.Backward(Time.deltaTime);
    } 
}

In your VideoController Script 在您的VideoController脚本中

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 这样可以使您控制倒带的速度,同时产生更流畅的效果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM