Skip to content

Commit

Permalink
Add more detail to time remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxocube committed Jan 6, 2025
1 parent f223b3a commit a744d36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MediaFeeder/MediaFeeder/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</Tooltip>

<Button Icon="@(IconType.Outline.ClockCircle)">
@Duration.Humanize()
@Duration.Humanize(2)
</Button>

<Tooltip Title="Shuffle">
Expand Down
8 changes: 4 additions & 4 deletions MediaFeeder/MediaFeeder/Components/Pages/Video.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
</TitleTemplate>
<SubtitleTemplate>
<span class="ant-page-header-heading-sub-title">
<a href="@($"/folder/{VideoObject?.Subscription?.ParentFolder?.Id}")">@VideoObject?.Subscription?.ParentFolder.Name</a>
<a href="@($"/folder/{VideoObject?.Subscription.ParentFolder?.Id}")">@VideoObject?.Subscription.ParentFolder?.Name</a>
&gt;
<a href="@($"/subscription/{VideoObject?.Subscription?.Id}")">@VideoObject?.Subscription?.Name</a>
<a href="@($"/subscription/{VideoObject?.Subscription.Id}")">@VideoObject?.Subscription.Name</a>
</span>
</SubtitleTemplate>

Expand Down Expand Up @@ -79,14 +79,14 @@
@if (Next != null)
{
<Tooltip Title="Remaining">
<Button>@UpNextCount, @UpNextDuration.Humanize()</Button>
<Button>@UpNextCount, @TotalDuration.Humanize(2)</Button>
</Tooltip>
}
</div>
</PageHeaderExtra>
</PageHeader>
<Content>
@if (VideoObject != null && Provider != null)
@if (VideoObject != null && Provider != null && PlaybackSession != null)
{
<DynamicComponent
Type="@Provider.VideoFrameView"
Expand Down
15 changes: 15 additions & 0 deletions MediaFeeder/MediaFeeder/Components/Pages/Video.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public sealed partial class Video : IDisposable

private int UpNextCount { get; set; }
private TimeSpan UpNextDuration { get; set; }
private TimeSpan TotalDuration { get; set; }

protected override async Task OnParametersSetAsync()
{
Expand Down Expand Up @@ -60,13 +61,27 @@ protected override async Task OnParametersSetAsync()
UpNextCount = more.Count;
UpNextDuration = TimeSpan.FromSeconds(Context.Videos.Where(v => more.Contains(v.Id)).Sum(static v => v.Duration));
}
else
{
UpNextDuration = TimeSpan.Zero;
}

PlaybackSession.Video = VideoObject;
PlaybackSession.Provider = Provider.Provider;
PlaybackSession.UpdateEvent += UpdateTimestamp;

UpdateTimestamp();
StateHasChanged();
}

private void UpdateTimestamp()
{
var remaining = VideoObject?.DurationSpan - PlaybackSession?.CurrentPosition;
TotalDuration = UpNextDuration + (remaining ?? TimeSpan.Zero);

InvokeAsync(StateHasChanged);
}

private async Task MarkWatched()
{
ArgumentNullException.ThrowIfNull(VideoObject);
Expand Down

0 comments on commit a744d36

Please sign in to comment.