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("當前視頻播放完成");
}
}