RemoteVideoControl.cs 3.0 KB

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