123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Video;
- using System;
- using UnityEngine.UI;
- using TMPro;
- public class RemoteVideoControl : MonoBehaviour
- {
- public GameObject Icon;
- public GameObject Stop;
- bool? isStart = true;
- // public VideoPlayer videoPlayer;
- public AVProVideoPlayer avProVideoPlayer;
- public Slider slider;
- //当前时间
- public Text currentTime;
- //影片时间
- public Text textTotalTime;
- //是否获取总时长
- private bool IsStart;
- //时 分的转换
- private int hour, mint;
- private float time;
-
- public void VideoStartSwitch()
- {
- // isStart = videoPlayer.isPlaying;
- isStart = avProVideoPlayer.IsPlaying();
- isStart = !isStart;
- Icon.SetActive(!isStart.Value);
- Stop.SetActive(isStart.Value);
- if (isStart.Value)
- {
- // videoPlayer?.Play();
- avProVideoPlayer?.Play();
- }
- else
- {
- // videoPlayer?.Pause();
- avProVideoPlayer?.Pause();
- }
- }
- private void Start()
- {
- IsStart = true;
- slider.onValueChanged.AddListener(delegate { ChangeVideo(slider.value); });
- StartCoroutine(VideoTimer());
- }
- public void ChangeVideo(float value)
- {
- //if (avProVideoPlayer.IsVideoReady())
- //{
- // float tempvalue = max * value;
- // time = tempvalue;
- // hour = (int)time / 60;
- // mint = (int)time % 60;
- // currentTime.text = string.Format("{0}:{1}", hour.ToString("00"), mint.ToString("00"));
- //}
- }
- float max;
- private IEnumerator VideoTimer()
- {
- while (true)
- {
- yield return new WaitForSeconds(0.5f);
- if (avProVideoPlayer.IsVideoReady()&& !AVideoSlide.isDown)
- {
- textTotalTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetMaxTimer() / 60).ToString("00"), (avProVideoPlayer.GetMaxTimer() % 60).ToString("00"));
- currentTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetNowTimer() / 60).ToString("00"), (avProVideoPlayer.GetNowTimer() % 60).ToString("00"));
- slider.value = avProVideoPlayer.GetNowTimer() / avProVideoPlayer.GetMaxTimer();
- if (slider.value > 0.99)
- {
- Icon.SetActive(true);
- Stop.SetActive(false);
- }
- }
- }
- }
- //void Update()
- //{
- // if (IsStart && avProVideoPlayer.IsVideoReady())
- // {
- // //max = avProVideoPlayer.GetMaxTimer();
- // //time = max;
- // //hour = (int)time / 60;
- // //mint = (int)time % 60;
- // // textTotalTime.text = string.Format("/ {0:D2}:{1:D2}", hour.ToString(), mint.ToString());
- // textTotalTime.text = string.Format("{0}:{1}",avProVideoPlayer.GetNowTimer().ToString("00"), avProVideoPlayer.GetMaxTimer().ToString("00"));
- // IsStart = !IsStart;
- // }
- //}
- }
|