素材巴巴 > 程序开发 >

Unity基于VideoPlayer组件发布WebGL播放视频【可播放暂停,有滑动条,脚本贴出】

程序开发 2023-09-12 20:02:29

首先搭建UI

 组件绑定情况:

 视频放在StreamingAssets文件夹下:

最后脚本绑定:

 FirstFrameImage在视频暂停是显示播放时隐藏,可以做成透明遮罩

Length是视频长度,把分钟转化成秒

 最后上脚本:

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Video;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;public class VideoController : MonoBehaviour
 {//视频名称public string videoName;//videoImage组件public GameObject VideoImage;//进度条组件public GameObject SliderController;//AudioSource组件public AudioSource audioSource;//播放按钮public GameObject PlayBtn;//暂停按钮public GameObject PauseBtn;//public GameObject CenterPlayBtn;//视频纹理public RenderTexture renderTexture;//视频第一帧public GameObject FirstFrameImage;//视频时长public float Length;//private bool isDrag = false;// Use this for initializationprivate void Awake(){InitVideo(renderTexture);}void Start(){#region 注册事件PlayBtn.GetComponent

需要测试工程的可参考这篇文章:

Unity发布WebGL播放视频【免插件,可快进后退,复制脚本即可使用】_3D菜鸟张三的博客-CSDN博客


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。