Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Timeline): show loading state if not played but duration is infinity #53

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/video-container/Video-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import { sourcesController, SourcesController } from "./sources";
const INIT_NATIVE_HLS_RE = /^((?!chrome|android).)*safari/i;

// In Safari on live streams video.duration = Infinity
const getVideoDuration = (video: HTMLVideoElement) => {
const getVideoDuration = (video: HTMLVideoElement): number => {
if (video.duration && video.duration !== Infinity) {
return video.duration
}
if (video.seekable.length > 0) {
return video.seekable.end(0)
}
return 0
return Infinity
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/components/video-timeline/Video-timeline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export class VideoTimeline extends DependentPropsMixin(LitElement) {
@state()
currentTime = 0;

@connect('played')
played: boolean

@state()
currentValue = 0;

Expand Down Expand Up @@ -128,9 +131,9 @@ export class VideoTimeline extends DependentPropsMixin(LitElement) {
};

render() {
const disabled = this.disabled || !this.canPlay;
const disabled = this.disabled || !this.canPlay || this.duration === Infinity;

if (!this.duration || this.duration === Infinity) return nothing
if (this.duration === Infinity && this.played) return nothing

return html`
<video-slider
Expand All @@ -145,7 +148,7 @@ export class VideoTimeline extends DependentPropsMixin(LitElement) {
: timeAsString(this.currentValue)}"
?disabled=${disabled}
?full=${this.live}
?loading=${!this.canPlay}
?loading=${!this.canPlay || this.duration === Infinity}
@changed=${this.handleChanged}
@hovering=${this.handleHover}
@hoverend=${this.handleHoverEnd}
Expand Down
1 change: 1 addition & 0 deletions src/components/video-timer/Video-timer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class VideoTimer extends LitElement {
currentTime: number;

get time() {
if (this.duration === Infinity) return 0
if (this.format === "left") return this.duration - this.currentTime;
if (this.format === "past") return this.currentTime;
return this.duration;
Expand Down