Skip to content

Commit

Permalink
fix(Timeline): show loading state if not played but duration is infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
timaramazanov committed Jul 2, 2024
1 parent afd4b8f commit 54aa4d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit 54aa4d3

Please sign in to comment.