Skip to content

Commit

Permalink
fix(player): clipped duration overwriting intrinsic duration
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Feb 3, 2024
1 parent 54cbc0c commit 3bab0d6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/vidstack/src/core/state/media-state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import throttle from 'just-throttle';
import { effect, onDispose, peek } from 'maverick.js';
import { DOMEvent, listenEvent } from 'maverick.js/std';

import { getTimeRangesEnd } from '..';
import { ListSymbol } from '../../foundation/list/symbols';
import { canChangeVolume } from '../../utils/support';
import type { MediaContext } from '../api/media-context';
Expand Down Expand Up @@ -411,11 +412,15 @@ export class MediaStateManager extends MediaPlayerController {
}

protected _onCanPlayDetail(detail: ME.MediaCanPlayDetail) {
const { seekable, seekableEnd, buffered, intrinsicDuration, canPlay } = this.$state;
const { seekable, buffered, intrinsicDuration, canPlay } = this.$state;

canPlay.set(true);
buffered.set(detail.buffered);
seekable.set(detail.seekable);
intrinsicDuration.set(seekableEnd());

// Do not fetch `seekableEnd` from `$state` as it might be clipped.
const seekableEnd = getTimeRangesEnd(detail.seekable) ?? Infinity;
intrinsicDuration.set(seekableEnd);
}

['duration-change'](event: ME.MediaDurationChangeEvent) {
Expand All @@ -425,16 +430,18 @@ export class MediaStateManager extends MediaPlayerController {
}

['progress'](event: ME.MediaProgressEvent) {
const { buffered, seekable, live, intrinsicDuration, seekableEnd } = this.$state,
const { buffered, seekable, live, intrinsicDuration } = this.$state,
detail = event.detail;

buffered.set(detail.buffered);
seekable.set(detail.seekable);

if (live()) {
// Do not fetch `seekableEnd` from `$state` as it might be clipped.
const seekableEnd = getTimeRangesEnd(detail.seekable) ?? Infinity;
intrinsicDuration.set(seekableEnd);
this.dispatch('duration-change', {
detail: seekableEnd(),
detail: seekableEnd,
trigger: event,
});
}
Expand Down

0 comments on commit 3bab0d6

Please sign in to comment.