RemoteVideoControl.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 OnEnable()
  43. {
  44. StartCoroutine(VideoTimer());
  45. }
  46. private void Start()
  47. {
  48. IsStart = true;
  49. slider.onValueChanged.AddListener(delegate { ChangeVideo(slider.value); });
  50. }
  51. public void ChangeVideo(float value)
  52. {
  53. //if (avProVideoPlayer.IsVideoReady())
  54. //{
  55. // float tempvalue = max * value;
  56. // time = tempvalue;
  57. // hour = (int)time / 60;
  58. // mint = (int)time % 60;
  59. // currentTime.text = string.Format("{0}:{1}", hour.ToString("00"), mint.ToString("00"));
  60. //}
  61. }
  62. float max;
  63. private IEnumerator VideoTimer()
  64. {
  65. while (true)
  66. {
  67. yield return new WaitForSeconds(0.5f);
  68. if (avProVideoPlayer.IsVideoReady()&& !AVideoSlide.isDown)
  69. {
  70. textTotalTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetMaxTimer() / 60).ToString("00"), (avProVideoPlayer.GetMaxTimer() % 60).ToString("00"));
  71. currentTime.text = string.Format("{0}:{1}", (avProVideoPlayer.GetNowTimer() / 60).ToString("00"), (avProVideoPlayer.GetNowTimer() % 60).ToString("00"));
  72. slider.value = avProVideoPlayer.GetNowTimer() / avProVideoPlayer.GetMaxTimer();
  73. if (slider.value > 0.99)
  74. {
  75. Icon.SetActive(true);
  76. Stop.SetActive(false);
  77. }
  78. }
  79. }
  80. }
  81. //void Update()
  82. //{
  83. // if (IsStart && avProVideoPlayer.IsVideoReady())
  84. // {
  85. // //max = avProVideoPlayer.GetMaxTimer();
  86. // //time = max;
  87. // //hour = (int)time / 60;
  88. // //mint = (int)time % 60;
  89. // // textTotalTime.text = string.Format("/ {0:D2}:{1:D2}", hour.ToString(), mint.ToString());
  90. // textTotalTime.text = string.Format("{0}:{1}",avProVideoPlayer.GetNowTimer().ToString("00"), avProVideoPlayer.GetMaxTimer().ToString("00"));
  91. // IsStart = !IsStart;
  92. // }
  93. //}
  94. }