1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Video;
- public class Mp4Item : BaseFilePrefabItem
- {
- public RawImage showVideo;
- public RectTransform rectTransform;
- // public VideoPlayer videoPlayer;
- public AVProVideoPlayer aVProVideoPlayer;
- public override void Init(FileConfig fileConfig)
- {
- Debug.Log("Hjj "+ fileConfig.Url);
- base.Init(fileConfig);
- if (!string.IsNullOrEmpty(fileConfig.Url))
- {
- string url = fileConfig.Url;
- //LangChaoRommMinIo.Instance.getFile(MQTTManager.Instance.roomId, fileConfig.Bucket, fileConfig.ObjectName, (RoomFileData rfd) => {
- // Debug.Log("rfd==>" + rfd.url);
- // Debug.Log("rfd==>" + rfd.bytes.Length);
- // url = rfd.url;
- //});
- if (!fileConfig.Url.Contains("http"))
- {
- url = "https://" + fileConfig.Url;
- }
- // videoPlayer.url = url;
- aVProVideoPlayer.SetUrl(url);
- }
- }
- protected override void Start()
- {
- base.Start();
- StartCoroutine(enumerator());
- }
- private IEnumerator enumerator()
- {
- while (!aVProVideoPlayer.IsVideoReady())
- {
- yield return null;
- }
- float standard_width = 150f;
- float standard_height = 84f;
- //float video_width = videoPlayer.texture.width;
- //float video_height = videoPlayer.texture.height;
- float video_width = aVProVideoPlayer.GetVideoWidth();
- float video_height = aVProVideoPlayer.GetVideoHeight();
- if (standard_width < video_width && standard_height > video_height)
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(standard_width, video_height * video_aspect);
- }
- else if (standard_width > video_width && standard_height < video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, standard_height);
- }
- else if (standard_width > video_width && standard_height > video_height)
- {
- if (standard_width / video_width > standard_height / video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- else
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- }
- else
- {
- if (standard_width / video_width > standard_height / video_height)
- {
- float video_aspect = standard_height / video_height;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- else
- {
- float video_aspect = standard_width / video_width;
- rectTransform.sizeDelta = new Vector2(video_width * video_aspect, video_height * video_aspect);
- }
- }
- }
- }
|