Skip to content

Commit

Permalink
Version bump; Fix positive offset not being set correctly if the vide…
Browse files Browse the repository at this point in the history
…o is not prepared. Seems to be new behavior from the Unity upgrade.
  • Loading branch information
Kevga committed Sep 7, 2021
1 parent 2a7ba1d commit c630196
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions BeatSaberCinema/Screen/PlaybackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public enum Scene { SoloGameplay, MultiplayerGameplay, Menu, Other }
private bool _previewWaitingForVideoPlayer = true;
private bool _previewWaitingForPreviewPlayer;
private DateTime _previewSyncStartTime;
private DateTime _audioSourceStartTime;
private float _offsetAfterPrepare;
private bool _previewIgnoreNextUpdate;

public VideoConfig? VideoConfig { get; private set; }
Expand Down Expand Up @@ -280,7 +282,6 @@ public async void StartPreview()
var startTime = 0f;
if (VideoConfig.offset < 0)
{
Log.Debug("Set preview start time to "+startTime);
startTime = -VideoConfig.GetOffsetInSec();
}

Expand All @@ -293,6 +294,7 @@ public async void StartPreview()
_previewIgnoreNextUpdate = true;
try
{
Log.Debug($"Preview start time: {startTime}, offset: {VideoConfig.GetOffsetInSec()}");
SongPreviewPlayerController.SongPreviewPlayer.CrossfadeTo(await VideoLoader.GetAudioClipForLevel(_currentLevel), -5f, startTime, _currentLevel.songDuration);
}
catch (Exception e)
Expand Down Expand Up @@ -718,7 +720,15 @@ private void PlayVideo(float startTime)
else
{
VideoPlayer.Play();
VideoPlayer.Player.time = totalOffset;
if (!VideoPlayer.Player.isPrepared)
{
_audioSourceStartTime = DateTime.Now;
_offsetAfterPrepare = totalOffset;
}
else
{
VideoPlayer.Player.time = totalOffset;
}
}
}

Expand Down Expand Up @@ -802,6 +812,14 @@ private IEnumerator PrepareVideoCoroutine(VideoConfig video)

private void OnPrepareComplete(VideoPlayer player)
{
if (_offsetAfterPrepare > 0)
{
var offset = (DateTime.Now - _audioSourceStartTime).TotalSeconds + _offsetAfterPrepare;
Log.Debug($"Adjusting offset after prepare to {offset}");
VideoPlayer.Player.time = offset;
}
_offsetAfterPrepare = 0;

if (_activeScene != Scene.Menu)
{
return;
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberCinema/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Sync up videos to play in the background of your beatmaps",
"author": "Dakari",
"gameVersion": "1.16.3",
"version": "1.4.12",
"version": "1.4.13",
"dependsOn": {
"BSIPA": "^4.2.0",
"BeatSaberMarkupLanguage": "^1.5.3",
Expand Down

0 comments on commit c630196

Please sign in to comment.