using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; using System; public class VideoTest : MonoBehaviour { public string m_Path; public FileInfo[] m_FileInfos; public GameObject m_VideoItemPrefab; // Start is called before the first frame update void Start() { m_FileInfos = LoadLocalFile(); //m_DeleteButton.onClick.AddListener(OnDeleteButton); //m_ExitSelectionButton.onClick.AddListener(OnExitSelectionMode); ReadFileInfos(); } public List tempStorageName = new List(); public List cdateTimes = new List(); public List VideoInformations = new List(); public void ReadFileInfos() { for (int i = 0; i < m_FileInfos.Length; i++) { if (m_FileInfos[i].Name.EndsWith(".mp4")) { VideoInformation information = new VideoInformation(m_FileInfos[i].CreationTime, m_FileInfos[i].Name, m_FileInfos[i].FullName, m_FileInfos[i]); VideoInformations.Add(information); } } //以时间排序 for (int j = 1; j <= VideoInformations.Count - 1; j++) { for (int i = 0; i < VideoInformations.Count - j; i++) { if (VideoInformations[i + 1].CreationTime > VideoInformations[i].CreationTime) { VideoInformation temp = VideoInformations[i]; VideoInformations[i] = VideoInformations[i + 1]; VideoInformations[i + 1] = temp; } } } for (int i = 0; i < VideoInformations.Count; i++) { InstantiateVideoItem(VideoInformations[i].m_VideoName, VideoInformations[i].m_VideoPath, VideoInformations[i].m_FileInfo); } } /// /// 实例化视频物体 /// /// /// public void InstantiateVideoItem(string info, string path, FileInfo fileinfo) { string practice = ""; string ship = ""; string subject = ""; string user = ""; #region //string time = ""; //int YY = 0; //int MM = 0; //int DD = 0; //int SS = 0; //int hh = 0; //int mm = 0; string[] infos = info.Split('$'); if (infos.Length == 6) { practice = infos[1]; ship = infos[2]; subject = infos[3]; user = infos[4]; //time = infos[5]; //string[] times = time.Split('-'); //YY = int.Parse(times[1]); //MM = int.Parse(times[2]); //DD = int.Parse(times[3]); //SS = int.Parse(times[4].TrimEnd('s')); //hh = SS / 3600; //mm = (SS - hh * 3600) / 60; } #endregion GameObject go = Instantiate(m_VideoItemPrefab, transform); VideoItem tempVI = go.GetComponent(); tempVI.m_Practice = practice; tempVI.m_Ship = ship; tempVI.m_Subject = subject; tempVI.m_User = user; //string temptime = string.Format("{0}/{1}/{2}", YY.ToString(), MM.ToString(), DD.ToString()); //tempVI.m_Time = temptime; tempVI.m_Time = fileinfo.CreationTime.ToString(); string[] ts = (fileinfo.LastWriteTime - fileinfo.CreationTime).ToString().Split(':'); int s = (int)float.Parse(ts[2]); tempVI.m_Length = string.Format("{0}:{1}:{2:D2}", ts[0], ts[1], s); tempVI.m_MyName = info; //string[] folders = path.Split('\\'); //Debug.Log("生成"+folders.Length); //string folder=""; //for (int i = 0; i < folders.Length; i++) //{ // if (folders[i].Trim().Equals("ScreenCaptures")) // tempVI.m_Folder = folder = folders[i + 1]; //} tempVI.m_Folder = fileinfo.Directory.Name; tempVI.m_MyPath = path; //tempVI.GetComponentInChildren().text = string.Format("{0}_{1}_{2}\n{3} {4:d2}:{5:d2}", user, subject, practice, temptime, hh, mm); tempVI.GetComponentInChildren().text = string.Format("{0}_{1}_{2}\n{3}", user, subject, practice, tempVI.m_Time); // m_TotalVideoItems.Add(tempVI); // SetTexture(subject, (sprite) => { tempVI.m_ThumbnailImage.sprite = sprite; }); //自动截取屏幕,读取截取文件 //string pngpath = Path.GetFullPath(Path.Combine(Application.dataPath,"..", "PrintScreens", folder, info.Split('.')[0]+".png"));//图片地址 //StartCoroutine(LoadTexture(pngpath, (texture) => { tempVI.m_RawImage.texture = texture; })); } /// /// 获取图片 /// /// /// /// IEnumerator LoadTexture(string url, Action callback) { Debug.Log(url); WWW www = new WWW(url); yield return www; if (www.isDone) { if (www.texture) callback?.Invoke(www.texture); } } public Queue videoItemsque = new Queue(); static string ScreenCapturePath; public static FileInfo[] LoadLocalFile() { FileInfo[] fileInfos = new FileInfo[0]; ScreenCapturePath = System.IO.Path.GetFullPath( System.IO.Path.Combine(Application.streamingAssetsPath, "ScreenCaptures") ); if (Directory.Exists(ScreenCapturePath)) { DirectoryInfo direction = new DirectoryInfo(ScreenCapturePath); fileInfos = direction.GetFiles("*", SearchOption.AllDirectories); } else Debug.LogError("路径‘" + ScreenCapturePath + "’不存在!"); return fileInfos; } } /// /// 视频信息类 /// public class VideoInformation { public DateTime CreationTime; public string m_VideoName; public string m_VideoPath; public FileInfo m_FileInfo; public VideoInformation(DateTime time, string name, string path, FileInfo fileInfo) { CreationTime = time; m_VideoName = name; m_VideoPath = path; m_FileInfo = fileInfo; } }