private void DeleteImage() { string name = video.CurrentImageName; string prefix = name.Split('_')[0]; VideoResourceAPI.Delete(Prefix2Type[prefix], name.TrimEnd(".png".ToArray())); Panels[(int)Prefix2Type[prefix]].UpdateAll(); }
private string preparedNewVideoName; // 暂存视频名,播放成功的才会被赋值给 CurrentVideoName public void Play(string name) { // 已经显示 Video if (canvasGroup.alpha > 0 && CurrentVideoName == name) { Click(); return; } Show(); ShowMask(); HideFailTip(); preparedNewVideoName = name; UrlPlay("file://" + VideoResourceAPI.FillVideoPath(name)); }
// 加载缩略图,若丢失缩略图则尝试生成 private Sprite LoadThumbnail(string imageName) { Sprite sprite = null; string path = Path.Combine(ThumbPath, imageName) + ImageSuffix; sprite = ResourceLoader.LoadSprite(path); if (sprite == null) { GameObject.Find("GetImage").GetComponent <GetImage>().GeneratePreviewImage( VideoResourceAPI.FillVideoPath(imageName), Path.Combine(Application.dataPath, "Resources", ThumbPath) + "/" ); StartCoroutine(ReloadEmptySprite()); } return(sprite); }
// 播放图片 public void PlayImage(string name) { Stop(); Show(); HideMask(); HideFailTip(); string fullPath = VideoResourceAPI.FillVideoPath(name); Texture2D texture = ResourceLoader.LoadTexture(fullPath); VideoRawImage.texture = texture; CurrentImageName = name; if (AutoResize) { Resize(texture.width, texture.height); } }
public void PlayHandle(object sender, string name) { string prefix = name.Split('_')[0]; VideoResourceAPI.VideoType type; try { type = VideoResourceAPI.Prefix2Type[prefix]; } catch (Exception) { Video_errorReceived(null, "[VideoManager.PlayHandle]: Convert Prefix to Type Error"); throw; } if (VideoResourceAPI.TypeIsVideo(type)) { Play(name); } else { PlayImage(name); } }
// 按钮事件 删除视频(图片) public void DeleteVideo() { // 删除图片调用 DeleteImage 单独处理 if (video.CurrentVideoName == "" && video.CurrentImageName == "") { return; } else if (video.CurrentImageName != "") { DeleteImage(); return; } string name = video.CurrentVideoName; string prefix = name.Split('_')[0]; VideoResourceAPI.Delete(Prefix2Type[prefix], name.TrimEnd(".mp4".ToArray())); video.Stop(); Panels[(int)Prefix2Type[prefix]].UpdateAll(); }
// outPath: Resource 下的路径 private static void OpenFile(string outDir, string prefix) { FileOpenDialog dialog = new FileOpenDialog(); dialog.structSize = Marshal.SizeOf(dialog); dialog.filter = ".mp4\0*.mp4"; dialog.file = new string(new char[256]); dialog.maxFile = dialog.file.Length; dialog.fileTitle = new string(new char[64]); dialog.maxFileTitle = dialog.fileTitle.Length; dialog.initialDir = UnityEngine.Application.dataPath; //默认路径 dialog.title = "Open File Dialog"; dialog.defExt = "mp4"; //显示文件的类型 //注意一下项目不一定要全选 但是0x00000008项不要缺少 dialog.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DialogShow.GetOpenFileName(dialog)) { string destDir = Application.dataPath + "/Resources/" + outDir + "/Videos/"; string videoName = prefix + "_" + dialog.fileTitle; File.Copy(dialog.file, destDir + videoName, true); Debug.Log("复制成功:" + destDir + videoName); GameObject.Find("GetImage").GetComponent <GetImage>().GeneratePreviewImage( VideoResourceAPI.FillVideoPath(videoName), Application.dataPath + "/Resources/" + outDir + "/Thumbnails/" ); } }
// 按钮事件 添加视频 public void AddVideo() { StartCoroutine(VideoResourceAPI.ImportFile((VideoType)curPanelIndex)); }