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

Next #49

Merged
merged 7 commits into from
Jun 3, 2024
Merged

Next #49

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
24 changes: 9 additions & 15 deletions src/components/video-container/Video-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import "../buttons/Play";
import { subtitlesController, SubtitlesController } from "./subtitles";
import { sourcesController, SourcesController } from "./sources";

const END_OF_STREAM_SECONDS = 99999;

const INIT_NATIVE_HLS_RE = /^((?!chrome|android).)*safari/i;

// In Safari on live streams video.duration = Infinity
Expand Down Expand Up @@ -84,13 +82,7 @@ export class VideoContainer extends LitElement {
@listen(Types.Command.play, { canPlay: true, castActivated: false })
async play() {
try {
const shouldRewindToEnd = !this.played && this.live;
await this.videos[0].play();
if (shouldRewindToEnd) {
window.requestAnimationFrame(() => {
this.videos[0].currentTime = END_OF_STREAM_SECONDS;
});
}
} catch (e) {
if (e.toString().includes("source")) {
this.command(Types.Command.initCustomHLS);
Expand Down Expand Up @@ -179,13 +171,15 @@ export class VideoContainer extends LitElement {

@listen(Types.Command.live, { canPlay: true, initialized: true })
enableLiveMode() {
dispatch(this, Types.Action.live, {
live: true,
});
window.requestAnimationFrame(() => {
this.videos[0].currentTime = END_OF_STREAM_SECONDS;
if (this.videos[0].paused && !this.castActivated) this.play();
});
dispatch(this, Types.Action.live, { live: true });
if (this.played) {
window.requestAnimationFrame(() => {
const seekable = this.videos[0].seekable;
const end = seekable?.length ? seekable.end(0) - 1 : 999999;
this.videos[0].currentTime = end;
this.play();
});
}
}

@listen(Types.Command.enableTextTrack)
Expand Down
6 changes: 3 additions & 3 deletions src/components/video-live-sign/Video-live-sign.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { unsafeCSS, LitElement, html } from "lit";
import { customElement } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import styles from "./Video-live-sign.styles.css?inline";
import { createCommand, connect } from "../../state";
import { createCommand, connect, dispatch, Types } from "../../state";

@customElement("video-live-sign")
export class VideoLiveSign extends LitElement {
Expand All @@ -18,12 +18,12 @@ export class VideoLiveSign extends LitElement {

private onClick = () => {
if (!this.live) {
this.command("live");
this.command(Types.Command.live);
}
};

firstUpdated(): void {
this.command("live");
dispatch(this, Types.Action.live, { live: true });
this.addEventListener("click", this.onClick);
}

Expand Down