You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.4 KiB
87 lines
2.4 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using System.IO; |
|
|
|
public class VideoItem : MonoBehaviour |
|
{ |
|
public Text RoomName; |
|
public Text Creator; |
|
public Text Name; |
|
public Text RecoedTime; |
|
public Button PlayButton; |
|
public Button DelectButton; |
|
public VideoData videoData; |
|
public Transform VideoRawImage; |
|
private Transform TipText; |
|
public Transform DelectPanel; |
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
PlayButton.onClick.AddListener(PlayButtonClick); |
|
DelectButton.onClick.AddListener(DelectButtonClick); |
|
VideoRawImage = GetComponentInParent<PlayVideoPanel>().transform.Find("VideoRawImagePanel"); |
|
TipText= GetComponentInParent<PlayVideoPanel>().transform.Find("TipText"); |
|
DelectPanel= GetComponentInParent<PlayVideoPanel>().transform.Find("DelectPanel"); |
|
} |
|
void PlayButtonClick() |
|
{ |
|
if (File.Exists(videoData.Url)) |
|
{ |
|
VideoRawImage.GetComponentInChildren<VideoRawImage>().Url = videoData.Url; |
|
VideoRawImage.gameObject.SetActive(true); |
|
} |
|
else |
|
{ |
|
TipText.gameObject.SetActive(true); |
|
StartCoroutine(closeTip()); |
|
} |
|
|
|
} |
|
void DelectButtonClick() |
|
{ |
|
DelectPanel.GetComponent<DelectPanel>().VideoItem = this.gameObject; |
|
DelectPanel.gameObject.SetActive(true); |
|
} |
|
public void Set(VideoData data) |
|
{ |
|
videoData = data; |
|
RoomName.text = data.RoomName; |
|
Creator.text = data.Creator; |
|
Name.text = data.Name; |
|
RecoedTime.text = data.RecoedTime; |
|
string path = data.Url.Replace(".mp4",".png"); |
|
GetSprit(path); |
|
} |
|
IEnumerator closeTip() |
|
{ |
|
yield return new WaitForSeconds(1f); |
|
TipText.gameObject.SetActive(false); |
|
} |
|
|
|
private void GetSprit(string path) |
|
{ |
|
StartCoroutine(Load(path)); |
|
} |
|
|
|
IEnumerator Load(string path) |
|
{ |
|
Debug.Log(path); |
|
WWW www = new WWW(path); |
|
yield return www; |
|
if (!string.IsNullOrEmpty(www.error)) |
|
{ |
|
Debug.Log(www.error); |
|
} |
|
else |
|
{ |
|
if (www.isDone) |
|
{ |
|
Texture2D tex = www.texture; |
|
|
|
GetComponent<Image>().sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); |
|
} |
|
} |
|
} |
|
}
|
|
|