TemplateVideo.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using RenderHeads.Media.AVProVideo;
  5. using UnityEngine;
  6. public class TemplateVideo : BaseTemPlate
  7. {
  8. private Navigator.VideoControl m_VideoCtr;
  9. private AVProVideoPlayer m_Video;
  10. protected override void OnEnable()
  11. {
  12. base.OnEnable();
  13. //if (GameManager.Instance.IsRuning && string.IsNullOrWhiteSpace(m_VideoCtr.VideoURL))
  14. //{
  15. // if (File.Exists(Data.localSavePath))
  16. // {
  17. // m_VideoCtr.VideoURL = Data.localSavePath;
  18. // }
  19. // else
  20. // {
  21. // m_VideoCtr.VideoURL = null;
  22. // }
  23. //}
  24. //m_VideoCtr.m_IsPlaying = false;
  25. //m_VideoCtr.PlayVideo();
  26. if (GameManager.Instance.IsRuning && string.IsNullOrWhiteSpace(m_Video.GetUrl()))
  27. {
  28. if (File.Exists(Data.localSavePath))
  29. {
  30. m_Video.SetUrl(Data.localSavePath);
  31. }
  32. else
  33. {
  34. m_Video.SetUrl(null);
  35. }
  36. }
  37. m_Video.transform.GetComponent<VideoPlayBtn>().m_IsPlaying = false;
  38. m_Video.transform.GetComponent<VideoPlayBtn>().PlayVideo();
  39. setScale = true;
  40. }
  41. private MediaPlayer MediaPlayer;
  42. private bool setScale;
  43. protected override void OnAwake()
  44. {
  45. base.OnAwake();
  46. // m_VideoCtr = transform.Find("Screen/Video").GetComponent<Navigator.VideoControl>();
  47. m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
  48. MediaPlayer = transform.Find("Screen/AVideo").GetComponent<MediaPlayer>();
  49. HideCollider();
  50. }
  51. private void Update()
  52. {
  53. if((MediaPlayer.Info.GetVideoHeight()!=0 || MediaPlayer.Info.GetVideoWidth()!=0) && setScale )
  54. {
  55. float temp = (float)MediaPlayer.Info.GetVideoHeight() / (float)MediaPlayer.Info.GetVideoWidth();
  56. MediaPlayer.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(56,56*temp);
  57. setScale = false;
  58. }
  59. }
  60. public override void SetData(MaterialObjValue value, int updateTime)
  61. {
  62. base.SetData(value, updateTime);
  63. if (!GameManager.Instance.IsRuning)
  64. {
  65. DownloadManager.Instance.AddDownloadData(Data);
  66. }
  67. else
  68. {
  69. if (File.Exists(Data.localSavePath))
  70. {
  71. // m_VideoCtr.VideoURL = Data.localSavePath;
  72. m_Video.SetUrl(Data.localSavePath);
  73. }
  74. else
  75. {
  76. // m_VideoCtr.VideoURL = null;
  77. m_Video.SetUrl(null);
  78. }
  79. }
  80. }
  81. public void SetData(string url)
  82. {
  83. Debug.Log(url);
  84. //if(m_VideoCtr ==null)
  85. // m_VideoCtr = transform.Find("Screen/Video").GetComponent<Navigator.VideoControl>();
  86. //m_VideoCtr.VideoURL = url;
  87. if (m_Video == null)
  88. m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
  89. m_Video.SetUrl(url);
  90. }
  91. public override void HideCollider()
  92. {
  93. base.HideCollider();
  94. }
  95. }