preload a little of video to make the video show

This commit is contained in:
Moon.eth
2026-07-29 16:43:03 +09:00
parent 81176654ba
commit b5288d7e03
2 changed files with 55 additions and 2 deletions
+13 -2
View File
@@ -24,6 +24,17 @@
function toggle(id: string): void {
revealed = { ...revealed, [id]: !revealed[id] }
}
/**
* Ask the browser to decode the first real frame while it loads metadata.
* The tiny media-fragment seek also makes the video's intrinsic dimensions
* available before playback on browsers that otherwise leave it at 300×150.
*/
function videoPreviewUrl(url: string): string {
const fragment = url.indexOf('#')
const base = fragment >= 0 ? url.slice(0, fragment) : url
return `${base}#t=0.001`
}
</script>
{#if attachments.length > 0}
@@ -39,12 +50,12 @@
{#if media.type === 'video' || media.type === 'gifv'}
<video
class="attachment-media"
src={media.url}
src={videoPreviewUrl(media.url)}
poster={media.preview_url ?? undefined}
controls
playsinline
loop={media.type === 'gifv'}
preload="none"
preload="metadata"
>
<!-- Remote media carries no caption track; declared so the
requirement is explicit rather than merely unmet. -->