Skip to content

Commit

Permalink
Try implementing remtoe control
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxocube committed Jan 6, 2025
1 parent 6b59d93 commit 79b91d0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
7 changes: 6 additions & 1 deletion MediaFeeder/MediaFeeder/Components/Pages/Video.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ protected override async Task OnParametersSetAsync()

ArgumentNullException.ThrowIfNull(user);

PlaybackSession ??= SessionManager.NewSession(user);
if (PlaybackSession == null)
{
PlaybackSession = SessionManager.NewSession(user);
PlaybackSession.SkipEvent += async () => await InvokeAsync(() => GoNext(false));
PlaybackSession.WatchEvent += async () => await InvokeAsync(() => GoNext(true));
}

VideoObject = await Context.Videos.SingleAsync(v => v.Id == Id && v.Subscription.UserId == user.Id);
StateHasChanged();
Expand Down
25 changes: 14 additions & 11 deletions MediaFeeder/MediaFeeder/Components/SessionInfo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@
</div>
}
</ChildContent>
@* <ActionTemplate> *@
@* <CardAction> *@
@* <Icon Type="@IconType.Outline.Eye" OnClick="@(() => Watch())"/> *@
@* Mark Watched *@
@* </CardAction> *@
@* <CardAction> *@
@* <Icon Type="@IconType.Outline.Delete" *@
@* OnClick="@(() => Delete())"/> *@
@* Delete Download *@
@* </CardAction> *@
@* </ActionTemplate> *@
<ActionTemplate>
<CardAction>
<Icon Type="@IconType.Outline.Pause" OnClick="@() => Session?.PlayPause()"/>
Pause
</CardAction>
<CardAction>
<Icon Type="@IconType.Outline.Eye" OnClick="@() => Session?.Watch()"/>
Mark Watched
</CardAction>
<CardAction>
<Icon Type="@IconType.Outline.FastForward" OnClick="@() => Session?.Skip()"/>
Skip
</CardAction>
</ActionTemplate>
</Card>

@code {
Expand Down
7 changes: 7 additions & 0 deletions MediaFeeder/MediaFeeder/PlaybackManager/PlaybackSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class PlaybackSession : IDisposable
private float? _rate;
private float? _loaded;
public event Action? UpdateEvent;
public event Action? PlayPauseEvent;
public event Action? WatchEvent;
public event Action? SkipEvent;

public void PlayPause() => PlayPauseEvent?.Invoke();
public void Watch() => WatchEvent?.Invoke();
public void Skip() => SkipEvent?.Invoke();

internal PlaybackSession(PlaybackSessionManager manager, AuthUser user)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,30 @@ protected override async Task OnParametersSetAsync()
_playingVideo = Video.Id;

await _player.InvokeVoidAsync("loadVideoById", Video.VideoId);

if (PlaybackSession != null)
PlaybackSession.PlayPauseEvent += PlayPause;
}
}

private async void PlayPause()
{
await InvokeAsync(async () =>
{
ArgumentNullException.ThrowIfNull(_player);

switch (_state)
{
case PlayerState.Paused:
await _player.InvokeVoidAsync("playVideo");
break;
case PlayerState.Playing:
await _player.InvokeVoidAsync("pauseVideo");
break;
}
});
}

[JSInvokable]
public async Task OnLibraryLoaded()
{
Expand Down

0 comments on commit 79b91d0

Please sign in to comment.