RemoteVideoControl.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Video;
  5. using System;
  6. using UnityEngine.UI;
  7. using TMPro;
  8. public class RemoteVideoControl : MonoBehaviour
  9. {
  10. public GameObject Icon;
  11. public GameObject Stop;
  12. bool? isStart = true;
  13. // public VideoPlayer videoPlayer;
  14. public AVProVideoPlayer avProVideoPlayer;
  15. public Slider slider;
  16. //当前时间
  17. public Text currentTime;
  18. //影片时间
  19. public Text textTotalTime;
  20. //是否获取总时长
  21. private bool IsStart;
  22. //时 分的转换
  23. private int hour, mint;
  24. private float time;
  25. public void VideoStartSwitch()
  26. {
  27. // isStart = videoPlayer.isPlaying;
  28. isStart = avProVideoPlayer.IsPlaying();
  29. isStart = !isStart;
  30. Icon.SetActive(!isStart.Value);
  31. Stop.SetActive(isStart.Value);
  32. if (isStart.Value)
  33. {
  34. // videoPlayer?.Play();
  35. avProVideoPlayer?.Play();
  36. }
  37. else
  38. {
  39. // videoPlayer?.Pause();
  40. avProVideoPlayer?.Pause();
  41. }
  42. }
  43. private void Start()
  44. {
  45. IsStart = true;
  46. slider.onValueChanged.AddListener(delegate { ChangeVideo(slider.value); });
  47. StartCoroutine(VideoTimer());
  48. }
  49. public void ChangeVideo(float value)
  50. {
  51. //if (avProVideoPlayer.IsVideoReady())
  52. //{
  53. // float tempvalue = max * value;
  54. // time = tempvalue;
  55. // hour = (int)time / 60;
  56. // mint = (int)time % 60;
  57. // currentTime.text = string.Format("{0}:{1}", hour.ToString("00"), mint.ToString("00"));
  58. //}
  59. }
  60. float max;
  61. private IEnumerator VideoTimer()
  62. {
  63. while (true)
  64. {
  65. yield return new WaitForSeconds(0.5f);
  66. if (avProVideoPlayer.IsVideoReady()&& !AVideoSlide.isDown)
  67. {
  68. textTotalTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetMaxTimer() / 60).ToString("00"), (avProVideoPlayer.GetMaxTimer() % 60).ToString("00"));
  69. currentTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetNowTimer() / 60).ToString("00"), (avProVideoPlayer.GetNowTimer() % 60).ToString("00"));
  70. slider.value = avProVideoPlayer.GetNowTimer() / avProVideoPlayer.GetMaxTimer();
  71. if (slider.value > 0.99)
  72. {
  73. Icon.SetActive(true);
  74. Stop.SetActive(false);
  75. }
  76. }
  77. }
  78. }
  79. //void Update()
  80. //{
  81. // if (IsStart && avProVideoPlayer.IsVideoReady())
  82. // {
  83. // //max = avProVideoPlayer.GetMaxTimer();
  84. // //time = max;
  85. // //hour = (int)time / 60;
  86. // //mint = (int)time % 60;
  87. // // textTotalTime.text = string.Format("/ {0:D2}:{1:D2}", hour.ToString(), mint.ToString());
  88. // textTotalTime.text = string.Format("{0}:{1}",avProVideoPlayer.GetNowTimer().ToString("00"), avProVideoPlayer.GetMaxTimer().ToString("00"));
  89. // IsStart = !IsStart;
  90. // }
  91. //}
  92. }