1、视频使用动态加载方式
self.videoPlayer = self.RawImage:GetComponent(UnityType.VideoPlayer)
self.rawImage = self.RawImage:GetComponent(UnityType.RawImage)
if is_nil(self.videoPlayer) then
self:closeCG(0)
end
local videoClip = CS.UnityEngine.Resources.Load("Video/video1")
if is_nil(videoClip) then
self:closeCG(0)
end
self.videoPlayer.clip = videoClip
self.videoState = GameEnum.VideoState.Load
self.videoPlayer:Prepare()
2、资源需要放到resource文件夹下,不能被打成ab
3、资源打包的时候不能被压缩,在android打包文件设置成不压缩
build.gradle文件:
aaptOptions {
noCompress = ['.resource']
}
可能出现的问题:
导出的Android版本播放视频只用声音没有画面,初始化VideoPlayer组件时,Android平台的报错提示是:E/Unity: Could not find material Hidden/VideoDecodeAndroid
解决办法:在Unity的Graphics Settings中的Always Included Shaders设置中添加"Hidden/VideoDecodeAndroid" shader,Unity有时会自动添加这个Shader,但有时不会,如果没有添加此Shader会导致播放视频时没有画面只有声音