Skip to content

Commit

Permalink
Allow position update from paused/stopped state (#1314)
Browse files Browse the repository at this point in the history
Allow position from paused/stopped state
  • Loading branch information
niksedk authored Aug 3, 2023
1 parent dc6ca49 commit 7dffe1f
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ partial class MediaManager : IDisposable
// The requests to keep display active are cumulative, this bool makes sure it only gets requested once
bool displayActiveRequested;

// States that allow changing position
MediaElementState[] allowUpdatePositionStates = new[]
{
MediaElementState.Playing,
MediaElementState.Paused,
MediaElementState.Stopped,
};

/// <summary>
/// The <see cref="DisplayRequest"/> is used to enable the <see cref="MediaElement.ShouldKeepScreenOn"/> functionality.
/// </summary>
Expand Down Expand Up @@ -163,8 +171,9 @@ protected virtual partial void PlatformUpdateShouldShowPlaybackControls()

protected virtual partial void PlatformUpdatePosition()
{
if (MediaElement is not null && Player is not null
&& MediaElement.CurrentState == MediaElementState.Playing)
if (MediaElement is not null
&& Player is not null
&& allowUpdatePositionStates.Contains(MediaElement.CurrentState))
{
MediaElement.Position = Player.MediaPlayer.Position;
}
Expand Down Expand Up @@ -198,8 +207,9 @@ protected virtual partial void PlatformUpdateShouldKeepScreenOn()

if (MediaElement.ShouldKeepScreenOn)
{
if (MediaElement?.CurrentState == MediaElementState.Playing
&& !displayActiveRequested)
if (MediaElement != null
&& allowUpdatePositionStates.Contains(MediaElement.CurrentState)
&& !displayActiveRequested)
{
DisplayRequest.RequestActive();
displayActiveRequested = true;
Expand Down

0 comments on commit 7dffe1f

Please sign in to comment.