Mp4Item.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Video;
  6. public class Mp4Item : BaseFilePrefabItem
  7. {
  8. public RawImage showVideo;
  9. public RectTransform rectTransform;
  10. // public VideoPlayer videoPlayer;
  11. public AVProVideoPlayer aVProVideoPlayer;
  12. public override void Init(FileConfig fileConfig)
  13. {
  14. Debug.Log("Hjj "+ fileConfig.Url);
  15. base.Init(fileConfig);
  16. if (!string.IsNullOrEmpty(fileConfig.Url))
  17. {
  18. string url = fileConfig.Url;
  19. //LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
  20. // Debug.Log("rfd==>" + rfd.url);
  21. // Debug.Log("rfd==>" + rfd.bytes.Length);
  22. // url = rfd.url;
  23. //});
  24. if (!fileConfig.Url.Contains("http"))
  25. {
  26. url = "https://" + fileConfig.Url;
  27. }
  28. // videoPlayer.url = url;
  29. aVProVideoPlayer.SetUrl(url);
  30. }
  31. }
  32. protected override void Start()
  33. {
  34. base.Start();
  35. StartCoroutine(enumerator());
  36. }
  37. private IEnumerator enumerator()
  38. {
  39. while (!aVProVideoPlayer.IsVideoReady())
  40. {
  41. yield return null;
  42. }
  43. float standard_width = 150f;
  44. float standard_height = 84f;
  45. //float video_width = videoPlayer.texture.width;
  46. //float video_height = videoPlayer.texture.height;
  47. float video_width = aVProVideoPlayer.GetVideoWidth();
  48. float video_height = aVProVideoPlayer.GetVideoHeight();
  49. if (standard_width < video_width && standard_height > video_height)
  50. {
  51. float video_aspect = standard_width / video_width;
  52. rectTransform.sizeDelta = new Vector2(standard_width, video_height * video_aspect);
  53. }
  54. else if (standard_width > video_width && standard_height < video_height)
  55. {
  56. float video_aspect = standard_height / video_height;
  57. rectTransform.sizeDelta = new Vector2(video_width * video_aspect, standard_height);
  58. }
  59. else if (standard_width > video_width && standard_height > video_height)
  60. {
  61. if (standard_width / video_width > standard_height / video_height)
  62. {
  63. float video_aspect = standard_height / video_height;
  64. rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
  65. }
  66. else
  67. {
  68. float video_aspect = standard_width / video_width;
  69. rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
  70. }
  71. }
  72. else
  73. {
  74. if (standard_width / video_width > standard_height / video_height)
  75. {
  76. float video_aspect = standard_height / video_height;
  77. rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
  78. }
  79. else
  80. {
  81. float video_aspect = standard_width / video_width;
  82. rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
  83. }
  84. }
  85. }
  86. }