Skip to content

Commit

Permalink
fix: live mode load time
Browse files Browse the repository at this point in the history
  • Loading branch information
Bitaru committed May 20, 2024
1 parent 6598df2 commit 59c597c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 108 deletions.
120 changes: 15 additions & 105 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 Expand Up @@ -248,99 +242,15 @@ export class VideoContainer extends LitElement {
this.hls?.destroy();

this.hls = new HLS({
debug: false,
capLevelToPlayerSize: true,
ignoreDevicePixelRatio: true,
abrMaxWithRealBitrate: true,
useMediaCapabilities: true,
preferManagedMediaSource: true,
maxMaxBufferLength: 30,
maxBufferSize: 60000000,
backBufferLength: 30,
minAutoBitrate: 0,
enableCEA708Captions: true,
enableWebVTT: true,
enableIMSC1: true,
renderTextTracksNatively: true,
captionsTextTrack1Label: "CC1",
captionsTextTrack1LanguageCode: "cc1",
captionsTextTrack2Label: "CC2",
captionsTextTrack2LanguageCode: "cc2",
captionsTextTrack3Label: "CC3",
captionsTextTrack3LanguageCode: "cc3",
captionsTextTrack4Label: "CC4",
captionsTextTrack4LanguageCode: "cc4",
enableDateRangeMetadataCues: true,
enableEmsgMetadataCues: true,
enableID3MetadataCues: true,
manifestLoadPolicy: {
default: {
maxTimeToFirstByteMs: null,
maxLoadTimeMs: 20000,
timeoutRetry: {
maxNumRetry: 2,
retryDelayMs: 0,
maxRetryDelayMs: 0,
},
errorRetry: {
maxNumRetry: 1,
retryDelayMs: 1000,
maxRetryDelayMs: 8000,
},
},
},
playlistLoadPolicy: {
default: {
maxTimeToFirstByteMs: 10000,
maxLoadTimeMs: 20000,
timeoutRetry: {
maxNumRetry: 2,
retryDelayMs: 0,
maxRetryDelayMs: 0,
},
errorRetry: {
maxNumRetry: 2,
retryDelayMs: 1000,
maxRetryDelayMs: 8000,
},
},
},
fragLoadPolicy: {
default: {
maxTimeToFirstByteMs: 10000,
maxLoadTimeMs: 12000,
timeoutRetry: {
maxNumRetry: 4,
retryDelayMs: 0,
maxRetryDelayMs: 0,
},
errorRetry: {
maxNumRetry: 6,
retryDelayMs: 1000,
maxRetryDelayMs: 8000,
},
},
},
steeringManifestLoadPolicy: {
default: {
maxTimeToFirstByteMs: 10000,
maxLoadTimeMs: 20000,
timeoutRetry: {
maxNumRetry: 2,
retryDelayMs: 0,
maxRetryDelayMs: 0,
},
errorRetry: {
maxNumRetry: 1,
retryDelayMs: 1000,
maxRetryDelayMs: 8000,
},
},
},
startLevel: -1,
testBandwidth: false,
abrEwmaDefaultEstimateMax: 10000000,
abrEwmaDefaultEstimate: 10000000,
enableWorker: true,
initialLiveManifestSize: 2,
liveSyncDurationCount: 5,
fragLoadingMaxRetry: 10,
manifestLoadingMaxRetry: 2,
levelLoadingMaxRetry: 4,
backBufferLength: navigator.userAgent.match(/Android/i) ? 0 : 30,
liveDurationInfinity: true,
});

if (this.muxData)
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 59c597c

Please sign in to comment.