知方号

知方号

unity导入视频并实现播放及进度条滑动<进度条百分比随进度条的改变而改变吗为什么>

unity导入视频并实现播放及进度条滑动

unity导入视频并实现播放及进度条滑动 一、创建界面二、导入脚本最终效果

一、创建界面

1.创建如下所示unity界面 button1:上一个视频 button2:播放/暂停 button3:下一个视频 vidotime:是一个text,显示视频时间 videoname:视频名称

2.具体界面如下所示

二、导入脚本

1.在RawImage中导入脚本,实现对视频播放/暂停,及切换视频功能

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using UnityEngine.Video;public class Video_Controller : MonoBehaviour{ private VideoPlayer videoplayer; private RawImage rawImage; private int currentClipIndex; public Text text_playorpause; public Button button_playorpause; public Button button_pre; public Button button_next; public VideoClip[] videoClips; void Start() { videoplayer = this.GetComponent(); rawImage = this.GetComponent(); currentClipIndex = 0; button_playorpause.onClick.AddListener(OnplayorpauseVideo); button_pre.onClick.AddListener(OnpreVideo); button_next.onClick.AddListener(OnnextVideo); } // Update is called once per frame void Update() { if (videoplayer.texture == null) { return; } rawImage.texture = videoplayer.texture; } private void OnplayorpauseVideo() { if (videoplayer.enabled == true) { if (videoplayer.isPlaying) { videoplayer.Pause(); text_playorpause.text = "播放"; } else if (!videoplayer.isPlaying) { videoplayer.Play(); text_playorpause.text = "暂停"; } } } private void OnpreVideo() { currentClipIndex -= 1; if (currentClipIndex

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。