コード例 #1
0
        /// <summary>
        /// Play the preview audio of the provided preview beatmap level.
        /// </summary>
        /// <param name="level">The level to play the audio from.</param>
        public async void CrossfadeAudioToLevelAsync(IPreviewBeatmapLevel level)
        {
            if (_songPreviewPlayerCrossfadingLevelID != level.levelID)
            {
                try
                {
                    _songPreviewPlayerCrossfadingLevelID = level.levelID;

                    if (_cancellationTokenSource != null)
                    {
                        _cancellationTokenSource.Cancel();
                    }
                    _cancellationTokenSource = new CancellationTokenSource();
                    CancellationToken token = _cancellationTokenSource.Token;

                    AudioClip audio = await level.GetPreviewAudioClipAsync(token);

                    token.ThrowIfCancellationRequested();

                    _songPreviewPlayer.CrossfadeTo(audio, level.previewStartTime, level.previewDuration);
                }
                catch (OperationCanceledException)
                {
                    if (_songPreviewPlayerCrossfadingLevelID == level.levelID)
                    {
                        _songPreviewPlayerCrossfadingLevelID = null;
                    }
                }
            }
        }
コード例 #2
0
 public Task <AudioClip> GetPreviewAudioClipAsync(CancellationToken cancellationToken)
 {
     if (_localPreview != null)
     {
         return(_localPreview.GetPreviewAudioClipAsync(cancellationToken));
     }
     return(Task.FromResult <AudioClip?>(null));
 }
コード例 #3
0
        private void DetailViewPreviewPressed()
        {
            if (previewPlaying)
            {
                StopPreview();
            }
            else
            {
                // start preview
                ScreenManager.Instance.PlayVideo();
                songPreviewPlayer.CrossfadeTo(selectedLevel.GetPreviewAudioClipAsync(new CancellationToken()).Result, 0, selectedLevel.previewDuration, 1f);

                previewPlaying = true;
            }
            _videoDetailViewController.SetPreviewState(previewPlaying);
        }
コード例 #4
0
        public PreviewBeatmapStub(string levelHash, IPreviewBeatmapLevel preview)
        {
            this.levelID      = preview.levelID;
            this.levelHash    = levelHash;
            this.isDownloaded = true;

            this.songName        = preview.songName;
            this.songSubName     = preview.songSubName;
            this.songAuthorName  = preview.songAuthorName;
            this.levelAuthorName = preview.levelAuthorName;

            this.beatsPerMinute = preview.beatsPerMinute;
            this.songDuration   = preview.songDuration;

            _coverTask    = preview.GetCoverImageAsync(CancellationToken.None);
            _rawCoverTask = GetCoverImageAsync(CancellationToken.None).ContinueWith <byte[]>(task => Utilities.Sprites.GetRaw(task.Result));
            _audioTask    = preview.GetPreviewAudioClipAsync(CancellationToken.None);
        }
コード例 #5
0
        public void ShowDifficultySelection(SongInfo song)
        {
            if (song == null)
            {
                return;
            }

            if (_difficultySelectionViewController == null)
            {
                _difficultySelectionViewController = BeatSaberUI.CreateViewController <DifficultySelectionViewController>();
                _difficultySelectionViewController.discardPressed      += DiscardPressed;
                _difficultySelectionViewController.playPressed         += (level, characteristic, difficulty) => { PlayPressed(level, characteristic, difficulty, _playerManagementViewController.modifiers); };
                _difficultySelectionViewController.levelOptionsChanged += UpdateLevelOptions;
            }

            if (!_roomNavigationController.viewControllers.Contains(_difficultySelectionViewController))
            {
                PushViewControllerToNavigationController(_roomNavigationController, _difficultySelectionViewController, null, true);
            }

            _difficultySelectionViewController.UpdateViewController(Client.Instance.isHost, roomInfo.perPlayerDifficulty);

            IPreviewBeatmapLevel selectedLevel = SongCore.Loader.CustomBeatmapLevelPackCollectionSO.beatmapLevelPacks.SelectMany(x => x.beatmapLevelCollection.beatmapLevels).FirstOrDefault(x => x.levelID == song.levelId);

            if (selectedLevel != null)
            {
                _difficultySelectionViewController.SetPlayButtonInteractable(false);
                _difficultySelectionViewController.SetLoadingState(true);

                LoadBeatmapLevelAsync(selectedLevel,
                                      (status, success, level) =>
                {
                    if (status == AdditionalContentModelSO.EntitlementStatus.NotOwned)
                    {
                        _difficultySelectionViewController.SetSelectedSong(selectedLevel);
                        _difficultySelectionViewController.SetPlayButtonInteractable(false);
                        Client.Instance.SendPlayerReady(false);
                        Client.Instance.playerInfo.updateInfo.playerState    = PlayerState.DownloadingSongs;
                        Client.Instance.playerInfo.updateInfo.playerProgress = 0f; selectedLevel.GetPreviewAudioClipAsync(new CancellationToken()).ContinueWith(
                            (res) =>
                        {
                            if (!res.IsFaulted)
                            {
                                PreviewPlayer.CrossfadeTo(res.Result, selectedLevel.previewStartTime, (res.Result.length - selectedLevel.previewStartTime));
                                _difficultySelectionViewController.SetSongDuration(res.Result.length);
                            }
                        });
                    }
                    else if (success)
                    {
                        _difficultySelectionViewController.SetSelectedSong(level);

                        if (level.beatmapLevelData.audioClip != null)
                        {
                            PreviewPlayer.CrossfadeTo(level.beatmapLevelData.audioClip, selectedLevel.previewStartTime, (level.beatmapLevelData.audioClip.length - selectedLevel.previewStartTime), 1f);
                            _difficultySelectionViewController.SetPlayButtonInteractable(true);
                            Client.Instance.SendPlayerReady(true);
                        }
                        else
                        {
                            _difficultySelectionViewController.SetPlayButtonInteractable(false);
                            Client.Instance.SendPlayerReady(false);
                        }

                        Client.Instance.playerInfo.updateInfo.playerState = PlayerState.Room;
                    }
                    else
                    {
                        _difficultySelectionViewController.SetSelectedSong(song);
                        _difficultySelectionViewController.SetPlayButtonInteractable(false);
                        Client.Instance.SendPlayerReady(false);
                        Client.Instance.playerInfo.updateInfo.playerState = PlayerState.Room;
                    }
                });
            }
            else
            {
                _difficultySelectionViewController.SetSelectedSong(song);
                Client.Instance.playerInfo.updateInfo.playerState = PlayerState.DownloadingSongs;
                Client.Instance.SendPlayerReady(false);
                _difficultySelectionViewController.SetPlayButtonInteractable(false);
                SongDownloader.Instance.RequestSongByLevelID(song.hash, (info) =>
                {
                    Client.Instance.playerInfo.updateInfo.playerState = PlayerState.DownloadingSongs;

                    songToDownload = info;

                    SongDownloader.Instance.DownloadSong(songToDownload,
                                                         (success) =>
                    {
                        void onLoaded(SongCore.Loader sender, Dictionary <string, CustomPreviewBeatmapLevel> songs)
                        {
                            SongCore.Loader.SongsLoadedEvent -= onLoaded;
                            Client.Instance.playerInfo.updateInfo.playerState = PlayerState.Room;
                            roomInfo.selectedSong.UpdateLevelId();
                            selectedLevel = songs.FirstOrDefault(x => x.Value.levelID == roomInfo.selectedSong.levelId).Value;
                            if (selectedLevel != null)
                            {
                                LoadBeatmapLevelAsync(selectedLevel,
                                                      (status, loaded, level) =>
                                {
                                    if (loaded)
                                    {
                                        PreviewPlayer.CrossfadeTo(level.beatmapLevelData.audioClip, level.previewStartTime, (level.beatmapLevelData.audioClip.length - level.previewStartTime));
                                        _difficultySelectionViewController.SetSelectedSong(level);
                                        _difficultySelectionViewController.SetPlayButtonInteractable(true);
                                        _difficultySelectionViewController.SetProgressBarState(false, 1f);
                                        Client.Instance.SendPlayerReady(true);
                                        Client.Instance.playerInfo.updateInfo.playerState = PlayerState.Room;
                                    }
                                    else
                                    {
                                        Plugin.log.Error($"Unable to load level!");
                                    }
                                });
                            }
                            else
                            {
                                Plugin.log.Error($"Level with ID {roomInfo.selectedSong.levelId} not found!");
                            }
                        }

                        SongCore.Loader.SongsLoadedEvent += onLoaded;

                        SongCore.Loader.Instance.RefreshSongs(false);
                        songToDownload = null;
                    },
                                                         (progress) =>
                    {
                        float clampedProgress = Math.Min(progress, 0.99f);
                        _difficultySelectionViewController.SetProgressBarState(true, clampedProgress);
                        Client.Instance.playerInfo.updateInfo.playerProgress = 100f * clampedProgress;
                    });
                });
            }
        }