Skip to content

Commit

Permalink
Merge pull request #47 from Uscreen-video/fix-live-mode
Browse files Browse the repository at this point in the history
Fix live mode
  • Loading branch information
Bitaru authored May 20, 2024
2 parents afb6ef3 + 8a219f7 commit bfbf76c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 7 additions & 13 deletions src/components/video-container/Video-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,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 +173,13 @@ 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(() => {
this.videos[0].currentTime = END_OF_STREAM_SECONDS;
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

0 comments on commit bfbf76c

Please sign in to comment.