如果 source是 videoclip(以下两种方式都可以):
_videoPlayer.Play();Debug.Log("time: " + _videoPlayer.clip.length);_videoPlayer.time = 10;
[SerializeField] VideoPlayer videoPlayer;public void SetClipWithTime(VideoClip clip, float time)
{StartCoroutine (SetTimeRoutine(clip, time));
}IEnumerator SetTimeRoutine (VideoClip clip, float time)
{if(videoPlayer.isPlaying){videoPlayer.Stop();}videoPlayer.clip = clip;videoPlayer.Prepare();yield return new WaitUntil (() => videoPlayer.isPrepared); yield return new WaitUntil (() => videoPlayer.canSetTime);videoPlayer.Play();videoPlayer.time = time;
}
如果是source是URL:
IEnumerator VideoPlay(){_videoPlayer.Prepare();yield return new WaitUntil(() => _videoPlayer.isPrepared);yield return new WaitUntil(() => _videoPlayer.canSetTime);// 检查是否完成初始化//while (!_videoPlayer.isPrepared)//{// yield return new WaitForSeconds(1f);// break;//}// 设置开头是第100帧_videoPlayer.frame += 100;// 开始播放_videoPlayer.Play();yield return new WaitForSeconds(0.01f);_videoPlayer.Pause();}
IEnumerator VideoPlay(){_videoPlayer.Prepare();// 检查是否完成初始化while (!_videoPlayer.isPrepared){yield return new WaitForSeconds(1f);break;}// 设置开头是第100帧_videoPlayer.frame += 100;// 开始播放_videoPlayer.Play();//yield return new WaitForSeconds(0.01f);//_videoPlayer.Pause();}