Beispiel #1
0
        private void StartSongPreview()
        {
            if (!SettingsStore.Instance.PluginEnabled || VideoConfig == null || !VideoConfig.IsPlayable)
            {
                return;
            }

            if ((_previewWaitingForPreviewPlayer || _previewWaitingForVideoPlayer || IsPreviewPlaying))
            {
                return;
            }

            if (_currentLevel != null && VideoLoader.IsDlcSong(_currentLevel))
            {
                return;
            }

            var delay        = DateTime.Now.Subtract(_previewSyncStartTime);
            var delaySeconds = (float)delay.TotalSeconds;

            Log.Debug($"Starting song preview playback with a delay of {delaySeconds}");

            var timeRemaining = _previewTimeRemaining - delaySeconds;

            if (timeRemaining > 1 || _previewTimeRemaining == 0)
            {
                PlayVideo(_previewStartTime + delaySeconds);
            }
            else
            {
                Log.Debug($"Not playing song preview, because delay was too long. Remaining preview time: {_previewTimeRemaining}");
            }
        }
        private void DownloadProcessExited(Process process, VideoConfig video)
        {
            var exitCode = process.ExitCode;

            if (exitCode != 0)
            {
                Log.Warn(_downloadLog.Length > 0 ? _downloadLog : "Empty youtube-dl log");

                video.DownloadState = DownloadState.Cancelled;
            }
            Log.Info($"Download process exited with code {exitCode}");

            if (video.DownloadState == DownloadState.Cancelled)
            {
                Log.Info("Cancelled download");
                VideoLoader.DeleteVideo(video);
                DownloadFinished?.Invoke(video);
            }
            else
            {
                process.Disposed -= DownloadProcessDisposed;
                _downloadProcesses.TryRemove(video, out _);
                video.DownloadState = DownloadState.Downloaded;
                video.NeedsToSave   = true;
                SharedCoroutineStarter.instance.StartCoroutine(WaitForDownloadToFinishCoroutine(video));
                Log.Info("Download finished");
            }
        }
        public void CancelDownload(VideoConfig video)
        {
            Log.Debug("Cancelling download");
            video.DownloadState = DownloadState.Cancelled;
            DownloadProgress?.Invoke(video);

            var success = _downloadProcesses.TryGetValue(video, out var process);

            if (success)
            {
                DisposeProcess(process);
            }
            VideoLoader.DeleteVideo(video);
        }
Beispiel #4
0
        private void GameSceneLoaded()
        {
            StopAllCoroutines();
            Log.Debug("GameSceneLoaded");

            _activeScene = Util.IsMultiplayer() ? Scene.MultiplayerGameplay : Scene.SoloGameplay;

            if (!Plugin.Enabled)
            {
                Log.Debug("Plugin disabled");
                VideoPlayer.Hide();
                return;
            }

            StopPlayback();
            VideoPlayer.Hide();

            if (BS_Utils.Plugin.LevelData.Mode == Mode.None)
            {
                Log.Debug("Level mode is None");
                return;
            }

            var bsUtilsLevel = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.difficultyBeatmap.level;

            if (_currentLevel?.levelID != bsUtilsLevel.levelID)
            {
                var video = VideoLoader.GetConfigForLevel(bsUtilsLevel);
                SetSelectedLevel(bsUtilsLevel, video);
            }

            if (VideoConfig == null || !VideoConfig.IsPlayable)
            {
                Log.Debug("No video configured or video is not playable");

                if (SettingsStore.Instance.CoverEnabled && (VideoConfig?.forceEnvironmentModifications == null || VideoConfig.forceEnvironmentModifications == false))
                {
                    ShowSongCover();
                }
                return;
            }

            if (VideoConfig.NeedsToSave)
            {
                VideoLoader.SaveVideoConfig(VideoConfig);
            }

            VideoPlayer.SetPlacement(Placement.CreatePlacementForConfig(VideoConfig, _activeScene, VideoPlayer.GetVideoAspectRatio()));

            //Fixes rough pop-in at the start of the song when transparency is disabled
            if (VideoConfig.TransparencyEnabled)
            {
                VideoPlayer.Show();
                VideoPlayer.ScreenColor = Color.black;
                VideoPlayer.ShowScreenBody();
            }

            SetAudioSourcePanning(0);
            VideoPlayer.Mute();
            StartCoroutine(PlayVideoAfterAudioSourceCoroutine(false));
        }
Beispiel #5
0
        public async void StartPreview()
        {
            if (VideoConfig == null || _currentLevel == null)
            {
                Log.Warn("No video or level selected in OnPreviewAction");
                return;
            }
            if (IsPreviewPlaying)
            {
                Log.Debug("Stopping preview");
                StopPreview(true);
            }
            else
            {
                Log.Debug("Starting preview");
                IsPreviewPlaying = true;

                if (VideoPlayer.IsPlaying)
                {
                    StopPlayback();
                }

                if (!VideoPlayer.IsPrepared)
                {
                    Log.Debug("Video not prepared yet");
                }

                //Start the preview at the point the video kicks in
                var startTime = 0f;
                if (VideoConfig.offset < 0)
                {
                    startTime = -VideoConfig.GetOffsetInSec();
                }

                if (SongPreviewPlayerController.SongPreviewPlayer == null)
                {
                    Log.Error("Failed to get reference to SongPreviewPlayer during preview");
                    return;
                }

                try
                {
                    Log.Debug($"Preview start time: {startTime}, offset: {VideoConfig.GetOffsetInSec()}");
                    var audioClip = await VideoLoader.GetAudioClipForLevel(_currentLevel);

                    if (audioClip != null)
                    {
                        SongPreviewPlayerController.SongPreviewPlayer.CrossfadeTo(audioClip, -5f, startTime, _currentLevel.songDuration, null);
                    }
                    else
                    {
                        Log.Error("AudioClip for level failed to load");
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    IsPreviewPlaying = false;
                    return;
                }

                //+1.0 is hard right. only pan "mostly" right, because for some reason the video player audio doesn't
                //pan hard left either. Also, it sounds a bit more comfortable.
                SetAudioSourcePanning(0.9f);
                StartCoroutine(PlayVideoAfterAudioSourceCoroutine(true));
                VideoPlayer.PanStereo = -1f;                 // -1 is hard left
                VideoPlayer.Unmute();
            }
        }