如何在Unity中倒带Video Player? [英] How to Rewind Video Player in Unity?

查看:983
本文介绍了如何在Unity中倒带Video Player?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Unity中倒带VideoPlayer,也正在使用新的VideoPlayer API和mp4.我尝试将播放速度设置为负数,但会暂停. 我当前的解决方案是

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

在我的快退按钮脚本中:

void Update ()
{

    if (rewind == true) {
        VideoController.Backward2Seconds();

    }

}

在我的VideoController脚本中

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

有更好的方法吗?因为太迟了.

Is there a better way? Because this is laggy.

推荐答案

不幸的是,恐怕您的第一次尝试是最好的尝试,而只是您的平台不支持它.它可以在其他设备上运行.根据 VideoPlayer文档:

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:

在您的RewindButton脚本中

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

在您的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

这篇关于如何在Unity中倒带Video Player?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆