1、在UI上添加腳本
添加UITexture腳本 用于顯示視頻
添加VideoPlayer
2、上代碼文章來源地址http://www.zghlxwxcb.cn/news/detail-559976.html
VideoPlayer m_Video;
UITexture m_Texture;
void Start(){
m_Video.started += OnStartVideo;//開始回調(diào)
m_Video.loopPointReached += EndWithVideoPlay;//結(jié)束回調(diào)
}
void PlayVideo(VideoClip vlip){
//可以引用外部視頻 也可以通過資源加載
RenderTexture targetTexture = RenderTexture.GetTemporary(m_Texture.width, m_Texture.height, 16);
m_Texture.mainTexture = targetTexture;
m_Video.clip = clip;
m_Video.targetTexture = targetTexture;
m_Video.isLooping = false;
m_Video.Play();
}
void OnStartVideo(VideoPlayer source) {
//todo 開始播放
}
void EndWithVideoPlay(VideoPlayer source) {
//TODO播放完成后事件
}
文章來源:http://www.zghlxwxcb.cn/news/detail-559976.html
到了這里,關(guān)于Unity播放視頻(一) VideoPlayer的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!