mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 17:36:18 -05:00
Resume videos and audio where the user left off; show progress on cards (#791)
* Resume videos and audio where the user left off; show progress on cards Videos and audio resume where the user left off, on the video page and in the file preview, and keep playing. `?t=` starts at an explicit time instead. useFileProgress saves how far the user is through a file: every 15 seconds while it changes, and a final save (a beacon, which survives the page closing) on pause, end, hiding the page, leaving it, or switching files. Each save is also kept in sessionStorage; on open the newer of that and the server's position wins, so coming straight back resumes exactly even if the final save is still in flight. Cards show a progress bar along the bottom of their poster. The dashboard's Recently Viewed Files gains All / Continue; Continue uses the new `in_progress` file search filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Progress review fixes: in_progress totals, latest dashboard request, preview viewed - The in_progress search filter skips the uncounted fast path and is part of the totals cache key, so Continue never reports All's (or the library's) count. - The dashboard's Recently Viewed hook applies only its latest response, and clears the list when switching All/Continue until the new files arrive. - POST /api/files/file returns `viewed`, so a preview can tell a file finished elsewhere from an older position this tab holds. - The progress hook tests restore Blob, fetch and sendBeacon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fbdf5bac82
commit
1ad451cddf
15 changed files with 666 additions and 38 deletions
|
|
@ -757,6 +757,18 @@ export function findPosterPath(file) {
|
|||
}
|
||||
}
|
||||
|
||||
/** How far the user is through a file, as a bar along the bottom of its poster. A full bar is finished. */
|
||||
export function ViewProgress({progress}) {
|
||||
if (!(progress > 0)) {
|
||||
return null;
|
||||
}
|
||||
const percent = Math.round(Math.min(progress, 1) * 100);
|
||||
return <div className='wrolpi-view-progress' role='progressbar' aria-label='Viewing progress'
|
||||
aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent}>
|
||||
<div className='wrolpi-view-progress-bar' style={{width: `${percent}%`}}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export function CardPoster({to, file, overlay}) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
|
@ -785,6 +797,7 @@ export function CardPoster({to, file, overlay}) {
|
|||
{imageLabel}
|
||||
<img alt='poster' src={posterPath}/>
|
||||
{overlay}
|
||||
<ViewProgress progress={file.progress}/>
|
||||
</>;
|
||||
|
||||
return <div className='wrolpi-card-poster'>
|
||||
|
|
@ -802,6 +815,7 @@ export function CardPoster({to, file, overlay}) {
|
|||
<div className='wrolpi-card-icon'>
|
||||
{imageLabel}
|
||||
<FileIcon file={file}/>
|
||||
<ViewProgress progress={file.progress}/>
|
||||
</div>
|
||||
</PreviewLink>
|
||||
} else if (!posterPath && to) {
|
||||
|
|
@ -810,6 +824,7 @@ export function CardPoster({to, file, overlay}) {
|
|||
<div className='wrolpi-card-icon' onClick={() => navigate(to)}>
|
||||
{imageLabel}
|
||||
<FileIcon file={file}/>
|
||||
<ViewProgress progress={file.progress}/>
|
||||
</div>
|
||||
</Link>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {CbzViewer} from "./CbzViewer";
|
|||
import {StlViewer} from "react-stl-viewer";
|
||||
import {Button, ButtonGroup, Header, Icon, IconButton, MediaGate, Menu, Modal, toast} from "./ui";
|
||||
import {useOneQuery} from "../hooks/customHooks";
|
||||
import {useMediaProgress} from "../hooks/useFileProgress";
|
||||
import {ShareButton} from "./Share";
|
||||
import {AddToPlaylistButton} from "./AddToPlaylist";
|
||||
import {pathDirectory} from "./FileBrowser";
|
||||
|
|
@ -157,6 +158,14 @@ function getImagePreviewModal(previewFile) {
|
|||
</React.Fragment>
|
||||
}
|
||||
|
||||
/** A <video> or <audio> which resumes where the user left off, and saves how far they got. */
|
||||
function PreviewMediaPlayer({as: Element, previewFile, path, style, children}) {
|
||||
const progressHandlers = useMediaProgress(path, previewFile);
|
||||
return <Element controls autoPlay={true} id="player" playsInline={true} style={style} {...progressHandlers}>
|
||||
{children}
|
||||
</Element>
|
||||
}
|
||||
|
||||
function getVideoPreviewModal(previewFile) {
|
||||
const url = getMediaPathURL(previewFile);
|
||||
const path = previewFile.primary_path ?? previewFile.path;
|
||||
|
|
@ -168,14 +177,10 @@ function getVideoPreviewModal(previewFile) {
|
|||
<Modal.Content>
|
||||
<Header as='h5'>{path['path']}</Header>
|
||||
<div className='preview-fit'>
|
||||
<video controls
|
||||
autoPlay={true}
|
||||
id="player"
|
||||
playsInline={true}
|
||||
style={{maxHeight: '100%', maxWidth: '100%'}}
|
||||
>
|
||||
<PreviewMediaPlayer as='video' previewFile={previewFile} path={path}
|
||||
style={{maxHeight: '100%', maxWidth: '100%'}}>
|
||||
<source src={url}/>
|
||||
</video>
|
||||
</PreviewMediaPlayer>
|
||||
</div>
|
||||
</Modal.Content>
|
||||
</React.Fragment>
|
||||
|
|
@ -192,14 +197,10 @@ function getAudioPreviewModal(previewFile) {
|
|||
{name}
|
||||
</Modal.Header>
|
||||
<Modal.Content>
|
||||
<audio controls
|
||||
autoPlay={true}
|
||||
id="player"
|
||||
playsInline={true}
|
||||
style={{width: '90%', maxWidth: '95%'}}
|
||||
>
|
||||
<PreviewMediaPlayer as='audio' previewFile={previewFile} path={path}
|
||||
style={{width: '90%', maxWidth: '95%'}}>
|
||||
<source src={url} type={type}/>
|
||||
</audio>
|
||||
</PreviewMediaPlayer>
|
||||
</Modal.Content>
|
||||
</React.Fragment>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import {
|
|||
toast,
|
||||
} from './ui';
|
||||
import {paletteColorNames} from '../themes/mantine';
|
||||
import {contrastingColor} from './Common';
|
||||
import {contrastingColor, ViewProgress} from './Common';
|
||||
import {navBarStyle, navColorNames, useNavColors} from '../themes/navColors';
|
||||
import {IconMenu2} from '@tabler/icons-react';
|
||||
import {BookmarkAddForms, BookmarkMenuItems, BookmarkTable} from './Bookmarks';
|
||||
|
|
@ -1032,6 +1032,31 @@ export function ThemeSamplePage() {
|
|||
rather than upscaled.
|
||||
</p>
|
||||
|
||||
<Header as='h4'>Viewing progress</Header>
|
||||
<CardGroup>
|
||||
{[
|
||||
['Part way through', 0.4],
|
||||
['Nearly done', 0.9],
|
||||
['Finished', 1],
|
||||
['Not started', null],
|
||||
].map(([label, progress]) => <Card
|
||||
key={label}
|
||||
title={label}
|
||||
meta={progress ? `${Math.round(progress * 100)}%` : 'no bar'}
|
||||
color='blue'
|
||||
media={<div className='wrolpi-card-poster'>
|
||||
<div className='wrolpi-card-poster-frame'>
|
||||
<img alt='' src={samplePoster(1280, 720)}/>
|
||||
<ViewProgress progress={progress}/>
|
||||
</div>
|
||||
</div>}
|
||||
/>)}
|
||||
</CardGroup>
|
||||
<p style={{fontSize: '0.75rem', color: 'var(--muted)', marginTop: 10}}>
|
||||
How far the user is through a video, audio file, ebook or comic, along the bottom
|
||||
of its poster. A full bar is finished; a file not yet started has none.
|
||||
</p>
|
||||
|
||||
<Header as='h4'>Meta, body and actions</Header>
|
||||
<CardGroup>
|
||||
{[
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ import {
|
|||
useTitle
|
||||
} from "./Common";
|
||||
import {VideoPlaceholder} from "./Placeholder";
|
||||
import {useChannel, useVideoCaptions, useVideoExtras} from "../hooks/customHooks";
|
||||
import {useChannel, useOneQuery, useVideoCaptions, useVideoExtras} from "../hooks/customHooks";
|
||||
import {useMediaProgress} from "../hooks/useFileProgress";
|
||||
import {Button, Grid, Header, Icon, Label, Loading, Panel, Placeholder, Tabs, TextInput} from "./ui";
|
||||
import {VideoCard} from "./Videos";
|
||||
import {TagsSelector} from "../Tags";
|
||||
|
|
@ -230,6 +231,12 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
video = videoFile.video;
|
||||
}
|
||||
|
||||
// `?t=120` starts at 2:00, rather than where the user left off.
|
||||
const [startTimeQuery] = useOneQuery('t');
|
||||
const startSeconds = startTimeQuery && Number.isFinite(parseFloat(startTimeQuery))
|
||||
? parseFloat(startTimeQuery) : null;
|
||||
const progressHandlers = useMediaProgress(videoFile?.primary_path, videoFile, {startSeconds});
|
||||
|
||||
// Seeks to the `seconds` on video player.
|
||||
const setVideoTime = (seconds) => {
|
||||
videoRef.current.currentTime = seconds;
|
||||
|
|
@ -456,6 +463,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
id="player"
|
||||
style={{width: '100%', marginTop: posterUrl ? '0.5em' : 0}}
|
||||
ref={videoRef}
|
||||
{...progressHandlers}
|
||||
>
|
||||
{videoSource}
|
||||
</audio>
|
||||
|
|
@ -467,6 +475,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
|
|||
playsInline={true}
|
||||
style={{maxWidth: '100%'}}
|
||||
ref={videoRef}
|
||||
{...progressHandlers}
|
||||
>
|
||||
{videoSource}
|
||||
{/* Only WebVTT captions can be displayed. */}
|
||||
|
|
|
|||
|
|
@ -1675,6 +1675,24 @@ html[data-theme="amber"] .wrolpi-card-tag {
|
|||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
/*
|
||||
* How far the user is through a file, along the bottom of its poster. Drawn from tokens beside the
|
||||
* image rather than inside it, like the tag mark, so night and amber color it themselves.
|
||||
*/
|
||||
.wrolpi-view-progress {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 0.25rem;
|
||||
background: var(--border);
|
||||
}
|
||||
|
||||
.wrolpi-view-progress-bar {
|
||||
height: 100%;
|
||||
background: var(--red);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- Statistics */
|
||||
/*
|
||||
* A statistic carries its own spacing rather than relying on a parent to supply
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue