Unity自带组件VideoPlayer的一些常用功能

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class Test : MonoBehaviour
{

    VideoPlayer videoPlayer;
    void Start()
    {
        //得到VideoPlay组件
        videoPlayer = GetComponent<VideoPlayer>();

        //当唤醒该对象时,视频不会自动播放
        //初始值为true,唤醒对象时自动播放视频
        videoPlayer.playOnAwake = false;

        //默认值为false,不循环播放,设置为ture循环播放
        videoPlayer.isLooping = true;

        //每次到达结尾值,我们都将添加ReachedLoop委托,注意这是委托,多次调用就会多次添加委托
        videoPlayer.loopPointReached += ReachedLoop;

        //播放引擎准备(能提高开始播放时的速度)
        videoPlayer.Prepare();
        //播放
        videoPlayer.Play();
        //暂停播放并保持当前时间不变
        videoPlayer.Pause();
        //停止播放并将当前时间设置为0
        videoPlayer.Stop();

        //VideoPlayer准备完成时调用
        videoPlayer.started += PrepareVideo;

        //调用play后立即调用
        videoPlayer.started += StartVideo;

        //当再次显示播放时,将上次视频的最后一帧销毁
        videoPlayer.targetTexture.Release();

    }

    void PrepareVideo(VideoPlayer videoPlayer) {
        Debug.Log("视频已经准备好了");
    }

    void StartVideo(VideoPlayer videoPlayer) {
        Debug.Log("视频已经在播放了");
    }


    void ReachedLoop(VideoPlayer videoPlay) {
        Debug.Log("当前视频播放完成");
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章