Unity:.webm视频将VideoPlayer冻结半秒

时间:2018-07-30 13:58:52

标签: unity3d webm alpha-transparency

我正在使用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;
    } 

0 个答案:

没有答案
相关问题