fix: prevent restart playback after transcoding completion

Closes #201
This commit is contained in:
talksik
2026-04-30 16:39:23 -07:00
parent 39ac3ed290
commit 6832c273cd
@@ -35,10 +35,20 @@ export const MediaParticleView = forwardRef<MediaParticleHandle, MediaParticleVi
}, ref) { }, ref) {
// Prefer the worker-produced iOS-playable variant when present so desktop // Prefer the worker-produced iOS-playable variant when present so desktop
// and mobile read the same canonical asset. Falls back to the original. // and mobile read the same canonical asset. Falls back to the original.
const activeObjectId = // Pin the choice for the lifetime of this particle: if a transcoded variant
particle.properties.transcoded_object_id ?? particle.properties.object_id; // arrives via Firestore mid-playback, swapping the <video> src would restart
const activeMime = // playback from 0. Keep whatever we picked first; the original plays fine in
particle.properties.transcoded_mime_type ?? particle.properties.mime_type; // Electron, and the transcoded variant will be picked up on the next view.
const pickedSourceRef = useRef<{ id: string; objectId: string; mime: string } | null>(null);
if (pickedSourceRef.current?.id !== particle.id) {
pickedSourceRef.current = {
id: particle.id,
objectId: particle.properties.transcoded_object_id ?? particle.properties.object_id,
mime: particle.properties.transcoded_mime_type ?? particle.properties.mime_type,
};
}
const activeObjectId = pickedSourceRef.current.objectId;
const activeMime = pickedSourceRef.current.mime;
const { data: url, error } = useDownloadUrl(activeObjectId); const { data: url, error } = useDownloadUrl(activeObjectId);
const { attachments } = useParticleAttachments(streamPath, particle.id); const { attachments } = useParticleAttachments(streamPath, particle.id);