当前位置:网站首页>Self use tool unity video player that monkeys can use
Self use tool unity video player that monkeys can use
2022-06-28 03:35:00 【Starve fish】
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class Movie : MonoBehaviour
{
[Tooltip(" Whether to hide when the program starts running UI,false For hiding ")] public bool OpenMovie_Awake = true;
[Header("Buttons")]
[Tooltip(" Play button ")] public Button Start;
[Tooltip(" Broadcasting speed +")] public Button SpeedUp;
[Tooltip(" Broadcasting speed -")] public Button SpeedDown;
[Header("UI")]
[Tooltip(" Input VideoPlayer")] public VideoPlayer VideoPlayers;
[Tooltip(" Broadcasting speed Text")] public Text SpeedShow;
[Tooltip(" Playback time and total duration Text")] public Text TimeShow;
[Header(" Slider bar . You need to add a sliding event to the slider ")]
[Tooltip(" Volume bar ")] public Slider Volume;
[Tooltip(" Progress bar ")] public Slider Times;
[Header(" Video playback speed ")]
[Range(0f, 1f)]
public float PlayBackSpeedChange = 0.5f;// Playback speed adjusted each time
[Range(0f, 5f)]
public float PlayBackSpeedMax = 3f;// Maximum playback speed
public static int PlayingURL;// Play current URL
public static string[] URL = { @"file://D:/Test/Movie01.mov"};// Video collection
void Awake()
{
VideoPlayers.GetComponent<VideoPlayer>().url = URL[0];
AddListerer();
_MovieOpend = true;
}
public void Update()// The playback speed text is adjusted here
{
SpeedShow.text = " Broadcasting speed X" + VideoPlayers.playbackSpeed.ToString("#0.0");
TimeShow.text = ($"{(int)VideoPlayers.time / 60}:{(VideoPlayers.time % 60).ToString("00")}/{(int)VideoPlayers.length / 60}:{(VideoPlayers.length % 60).ToString("00")}");
if (VideoPlayers.frameRate / VideoPlayers.frameCount > 0)// Progress bar
{
if (!Input.GetMouseButton(0) || _volumedraging)
Times.value = (float)VideoPlayers.time / (float)VideoPlayers.length;
}
if (Input.GetMouseButtonUp(0)) _volumedraging = false;// Prevent sliding the volume bar to lock the progress bar
}
/// <summary>
/// Progress bar
/// </summary>
public void Ondrag()
{
if (Input.GetMouseButton(0) && !_volumedraging)
VideoPlayers.time = Times.value * (float)VideoPlayers.length;
}
/// <summary>
/// The volume
/// </summary>
public void VolumeDrag()
{
_volumedraging = true;
VideoPlayers.SetDirectAudioVolume(0, Volume.value);
}
/// <summary>
/// Add listeners for all buttons
/// </summary>
void AddListerer()
{
Start.onClick.AddListener(() =>// Play
{
if (_Pauseing)
{
VideoPlayers.playbackSpeed = 1f;
Start.gameObject.transform.Find("Text").GetComponent<Text>().text = " Pause ";
_Pauseing = false;
}
else
{
VideoPlayers.playbackSpeed = 0f;
Start.gameObject.transform.Find("Text").GetComponent<Text>().text = " Play ";
_Pauseing = true;
}
});
SpeedUp.onClick.AddListener(() =>
{
if (VideoPlayers.playbackSpeed < PlayBackSpeedMax)
VideoPlayers.playbackSpeed += PlayBackSpeedChange;
});
SpeedDown.onClick.AddListener(() =>
{
if (VideoPlayers.playbackSpeed > 0f)
VideoPlayers.playbackSpeed -= PlayBackSpeedChange;
});
}
bool _MovieOpend;
bool _Pauseing = false;
bool _volumedraging;
}
design sketch
边栏推荐
猜你喜欢
[iptables & ICMP] description of ICMP Protocol in iptables default policy
音视频技术开发周刊 | 251
Hot! Yolov6's fast and accurate target detection framework is open source (with source code download)
Object类,以及__new__,__init__,__setattr__,__dict__
「运维有小邓」监控文件及文件夹变更
2022 safety officer-c certificate examination question bank simulated examination platform operation
mysql获取当前时间是一年的第多少天
Idea auto generate code
__ getitem__ And__ setitem__
"9 No" principle and "5 measurement dimensions" of extensible system
随机推荐
How to automatically add author, time, etc. to eclipse
在excel文件上设置下拉选项
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
SSH框架的搭建(下)
荣耀v8 真机调试时不显示 Logcat 日志的解决办法
xml&nbsp;文件的读写
Go speed
学习---有用的资源
华为设备WLAN基本业务配置命令
WebSocket(简单体验版)
ETCD数据库源码分析——集群间网络层服务端RaftHandler
What is the difference between slice and array in go question bank 12?
建立自己的网站(17)
基于 WPF 的酷炫 GUI 窗口的简易实现
__getitem__和__setitem__
数据库系列之MySQL和TiDB中慢日志分析
项目实战!手把手教你 Jmeter 性能测试
CURDATE()和NOW()区别
Is it better for a novice to open a securities account? Is it safe to open a stock trading account
导入Excel文件,解决跳过空白单元格不读取,并且下标前移的问题,以及RETURN_BLANK_AS_NULL报红