using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class VideoController : MonoBehaviour
{
//设置VideoPlayer、RawImage和当前播放视频索引参数
private VideoPlayer videoPlayer;
private RawImage rawImage;
[SerializeField]
Image myImage;
// private int currentClipIndex;
//设置相关文本和按钮参数以及视频列表
public Text text_PlayOrPause;
public Button button_PlayOrPause;
private void Awake()
{
text_PlayOrPause.text = "暂停";
// Image/pic 在 Assets/Resources/目录下
myImage.sprite = Resources.Load("zanting", typeof(Sprite)) as Sprite;
}
void Start()
{
//获取VideoPlayer和RawImage组件,以及初始化当前视频索引
videoPlayer = this.GetComponent<VideoPlayer>();
rawImage = this.GetComponent<RawImage>();
// currentClipIndex = 0;
//设置相关按钮监听事件
button_PlayOrPause.onClick.AddListener(OnPlayOrPauseVideo);
}
void Update()
{
//没有视频则返回,不播放
if (videoPlayer.texture == null)
{
return;
}
//渲染视频到UGUI上
rawImage.texture = videoPlayer.texture;
}
private void OnPlayOrPauseVideo()
{
//判断视频播放情况,播放则暂停,暂停就播放,并更新相关文本
if (videoPlayer.isPl
Unity使用RawImage播放视频带有播放暂停功能滑动条可控制快进后退
最新推荐文章于 2024-06-15 00:15:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)