private void MissionSelectionDidActivate(bool firstActivation, ViewController.ActivationType activationType) { selectedVideo = null; selectedLevel = null; Activate(); }
// private VideoPlayer.EventHandler videoPlayerOnprepareCompleted; public IEnumerator PrepareVideoCoroutine(VideoData video) { // if (videoPlayerOnprepareCompleted != null) videoPlayer.prepareCompleted -= videoPlayerOnprepareCompleted; currentVideo = video; if (video == null) { videoPlayer.url = null; vsRenderer.material.color = Color.clear; try { videoPlayer.Prepare(); // Plugin.logger.Notice("Prepared null video"); } catch { Plugin.logger.Notice("Oops guess I can't prepare null video"); } yield break; } videoPlayer.source = UnityEngine.Video.VideoSource.Url; videoPlayer.Pause(); if (video.isLocal) { Plugin.logger.Info($"Video is Local file"); if (video.downloadState != DownloadState.Downloaded) { yield break; } videoPlayer.isLooping = video.loop; Plugin.logger.Info($"Video has been cut: {video.HasBeenCut}"); string videoPath; yield return (videoPath = video.CorrectVideoPath); // VideoLoader.GetVideoPath(video, video.HasBeenCut)); Plugin.logger.Info($"Loading video: {videoPath}"); videoPlayer.Pause(); var lockTimer = new Stopwatch(); lockTimer.Start(); var videoFileInfo = new FileInfo(videoPath); var lockWaitTicks = 6 * TimeSpan.TicksPerSecond; if (videoPlayer.url != videoPath) { yield return(new WaitUntil(() => !IsFileLocked(videoFileInfo) || lockTimer.ElapsedTicks > lockWaitTicks)); yield return(videoPlayer.url = videoPath); } lockTimer.Stop(); if (lockTimer.ElapsedTicks > lockWaitTicks && IsFileLocked(videoFileInfo)) { var exception = new Exception("File Locked"); Plugin.logger.Error(exception); throw exception; } yield return(offsetSec = video.offset / 1000f); // ms -> s var correctVideoTime = video.offset >= 0 ? offsetSec : 0; var correctVideoFrame = (int)Math.Round(videoPlayer.frameRate * correctVideoTime); yield return(vsRenderer.material.color = Color.clear); videoPlayer.Prepare(); // videoPlayerOnprepareCompleted = source => SeekVideoToTime(correctVideoTime); // videoPlayer.prepareCompleted += videoPlayerOnprepareCompleted; Plugin.logger.Debug("Preparing"); yield return(new WaitUntil(() => { // Plugin.logger.Debug($"{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.canSetTime ? "canSetTime" : "Not canSetTime")}"); return videoPlayer.isPrepared; })); Plugin.logger.Info("Prepared video"); // Plugin.logger.Debug($"{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.canSetTime ? "canSetTime" : "Not canSetTime")}"); // Plugin.logger.Debug("Seeking"); // while (Math.Abs(videoPlayer.time - correctVideoTime) > .050 || (videoPlayer.frame - correctVideoFrame) > 2) // { yield return(SeekVideoToTime(correctVideoTime)); // } Plugin.logger.Info( $"Times are {videoPlayer.time}:{correctVideoTime}\tFrames are {videoPlayer.frame}:{correctVideoFrame}\t{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.isPaused ? "Paused" : "Not Paused")}"); } else { Plugin.logger.Info($"Video is located at {video.videoPath}"); videoPlayer.url = video.videoPath; // set url to the non-local path yield return(offsetSec = video.offset / 1000f); // ms -> s var correctVideoTime = video.offset >= 0 ? offsetSec : 0; var correctVideoFrame = (int)Math.Round(videoPlayer.frameRate * correctVideoTime); yield return(vsRenderer.material.color = Color.clear); videoPlayer.Prepare(); // videoPlayerOnprepareCompleted = source => SeekVideoToTime(correctVideoTime); // videoPlayer.prepareCompleted += videoPlayerOnprepareCompleted; Plugin.logger.Debug("Preparing"); yield return(new WaitUntil(() => { // Plugin.logger.Debug($"{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.canSetTime ? "canSetTime" : "Not canSetTime")}"); return videoPlayer.isPrepared; })); Plugin.logger.Info("Prepared video"); // Plugin.logger.Debug($"{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.canSetTime ? "canSetTime" : "Not canSetTime")}"); // Plugin.logger.Debug("Seeking"); // while (Math.Abs(videoPlayer.time - correctVideoTime) > .050 || (videoPlayer.frame - correctVideoFrame) > 2) // { yield return(SeekVideoToTime(correctVideoTime)); // } Plugin.logger.Info( $"Times are {videoPlayer.time}:{correctVideoTime}\tFrames are {videoPlayer.frame}:{correctVideoFrame}\t{(videoPlayer.isPrepared ? "Prepared" : "Not Prepared")}\t{(videoPlayer.isPaused ? "Paused" : "Not Paused")}"); } }