首页 > 解决方案 > Unity:VideoPlayer 使用 .webm 视频冻结半秒

问题描述

我正在使用 Windows 10 Pro 和 unity 5.6.4p2。我有 2 架带有视频播放器组件的飞机(两个视频都是从流媒体资源文件夹中加载的。一个视频是 .mp4,另一个是具有透明度(alpha 通道)的 .webm。我在飞机上附加了一些脚本,但是无论有没有脚本,我都有这个问题,所以不需要发布代码。

webm 视频(6 秒长)循环播放,每 10-15-20 秒或更长时间,它会冻结半秒。使用 mp4 视频我没有问题。

在编辑器中没有冻结,当我在构建中尝试它时,它给了我问题。

我不知道该怎么办。Unity 的质量选项有什么我可以尝试的吗?我尝试了 5 个不同的透明视频(webm),但它们是由同一个人用相同的方法制作的。可能是文件?

与此同时,我正在寻找另一个 .webm 进行一些测试。

谢谢!

编辑(播放视频的代码):

IEnumerator playVideo(string name)
    {
        blackScreen.SetActive (true);
        wait = true;

        videoPlayer = gameObject.GetComponent<VideoPlayer>();
        audioSource = gameObject.GetComponent<AudioSource>();

        //Disable Play on Awake for both Video and Audio
        videoPlayer.playOnAwake = false;
        audioSource.playOnAwake = false;
        audioSource.Pause();

        videoPlayer.source = VideoSource.Url;
        if (!alpha) {
            videoPlayer.url = Application.streamingAssetsPath + "/Scenarios/" + 
    name + ".mp4";
        } else {
            videoPlayer.url = Application.streamingAssetsPath + "/Scenarios/" + 
    name + ".webm";
        }
        videoPlayer.EnableAudioTrack(0, true);
        videoPlayer.SetTargetAudioSource(0, audioSource);

        //Set video To Play then prepare Audio to prevent Buffering
        videoPlayer.clip = videoToPlay;
        currentVideoName = name;
        videoPlayer.Prepare();

        //Wait until video is prepared
        WaitForSeconds waitTime = new WaitForSeconds(0.1f);
        while (!videoPlayer.isPrepared)
        {
            Debug.Log("Preparing Video");

            yield return waitTime;

            break;
        }

        Debug.Log("Done Preparing Video");
        videoPlayer.gameObject.GetComponent<MeshRenderer> ().enabled = true;
        blackScreen.SetActive (false);
        //Assign the Texture from Video to RawImage to be displayed
        image.texture = videoPlayer.texture;

        //Play Video
        videoPlayer.Play();
        ready = true;
        //Play Sound
        audioSource.Play();
        Debug.Log("Playing Video");
        while (videoPlayer.isPlaying)
        {
            wait = true;
            yield return null;
        }
        Debug.Log("Done Playing Video");
        wait = false;
    } 

标签: unity3dwebmalpha-transparency

解决方案


推荐阅读