Skip to content

Commit a14282f

Browse files
committed
Fix pause spam and stop remote correctly
- Fix pause spam because I was being dumb and fix remote pause correctly - Fix stopping the remote video when the owner switches stream <-> video
1 parent 4dfb6ce commit a14282f

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Assets/USharpVideo/Scripts/USharpVideoPlayer.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private void OnDisable()
133133

134134
void StartVideoLoad(VRCUrl url)
135135
{
136+
Debug.Log("[USharpVideo] Started video load");
136137
_currentPlayer.LoadURL(url);
137138
_statusStr = "Loading video...";
138139
SetStatusText(_statusStr);
@@ -382,6 +383,7 @@ void UpdateVideoLoad()
382383
}
383384
else
384385
{
386+
Debug.Log("[USharpVideo] Retrying load");
385387
_currentPlayer.LoadURL(_syncedURL);
386388
}
387389
}
@@ -396,7 +398,8 @@ void ChangePlayerMode()
396398
if (currentPlayerMode == _localPlayerMode)
397399
return;
398400

399-
StopVideo();
401+
_currentPlayer.Stop();
402+
_locallyPaused = _ownerPaused = false;
400403

401404
Material screenMaterial = screenRenderer.sharedMaterial;
402405

@@ -444,17 +447,10 @@ public override void OnDeserialization()
444447

445448
if (!_ownerPaused && _locallyPaused)
446449
{
450+
Debug.Log("[USharpVideo] Play");
447451
_currentPlayer.Play();
448452
_locallyPaused = false;
449453
}
450-
else
451-
{
452-
_currentPlayer.Pause();
453-
_locallyPaused = true;
454-
}
455-
456-
//if (_syncedURL != null)
457-
// Debug.Log("[USharpVideo] Received URL " + _syncedURL);
458454

459455
if (_videoNumber == _loadedVideoNumber)
460456
return;
@@ -508,12 +504,12 @@ private void Update()
508504
if (_localPlayerMode != currentPlayerMode)
509505
ChangePlayerMode();
510506

511-
if (_localPlayerMode == PLAYER_MODE_STREAM)
512-
screenRenderer.sharedMaterial.SetTexture("_EmissionMap", streamRTSource.sharedMaterial.GetTexture("_MainTex"));
507+
float currentTime = _currentPlayer.GetTime();
513508

514-
if (currentPlayerMode == PLAYER_MODE_VIDEO)
509+
bool isVideoPlayMode = currentPlayerMode == PLAYER_MODE_VIDEO;
510+
511+
if (isVideoPlayMode)
515512
{
516-
float currentTime = _currentPlayer.GetTime();
517513
float duration = _currentPlayer.GetDuration();
518514
string totalTimeStr = System.TimeSpan.FromSeconds(duration).ToString(@"hh\:mm\:ss");
519515

@@ -532,22 +528,27 @@ private void Update()
532528

533529
videoProgressSlider.value = Mathf.Clamp01(currentTime / (duration > 0f ? duration : 1f));
534530
}
535-
536-
// Keep the target time the same while paused
537-
if (_ownerPaused)
538-
{
539-
_videoStartNetworkTime = (float)Networking.GetServerTimeInSeconds() - currentTime;
540-
541-
_currentPlayer.Pause();
542-
_locallyPaused = true;
543-
}
544531
}
545532
else // Stream player
546533
{
547534
if (!string.IsNullOrEmpty(_statusStr))
548535
SetStatusText("");
536+
537+
screenRenderer.sharedMaterial.SetTexture("_EmissionMap", streamRTSource.sharedMaterial.GetTexture("_MainTex"));
549538
}
550-
539+
540+
if (_ownerPaused)
541+
{
542+
if (isVideoPlayMode)
543+
{
544+
// Keep the target time the same while paused
545+
_videoStartNetworkTime = (float)Networking.GetServerTimeInSeconds() - currentTime;
546+
}
547+
548+
_currentPlayer.Pause();
549+
_locallyPaused = true;
550+
}
551+
551552
UpdateVideoLoad();
552553

553554
if (isOwner || !_waitForSync)

0 commit comments

Comments
 (0)