diff --git a/demo/src/App.tsx b/demo/src/App.tsx index 1c70dfb6..5bd98e33 100644 --- a/demo/src/App.tsx +++ b/demo/src/App.tsx @@ -29,6 +29,8 @@ const players = [ type Player = (typeof players)[number]; const streamUrls = { + radioStream: + "https://streamvideo.luxnet.ua/maximum/smil:maximum.stream.smil/playlist.m3u8", hlsBigBunnyBuck: "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", hlsByteRangeVideo: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8", diff --git a/packages/p2p-media-loader-hlsjs/src/engine.ts b/packages/p2p-media-loader-hlsjs/src/engine.ts index 8f91f3bb..3b9536da 100644 --- a/packages/p2p-media-loader-hlsjs/src/engine.ts +++ b/packages/p2p-media-loader-hlsjs/src/engine.ts @@ -4,6 +4,7 @@ import type { LevelUpdatedData, ManifestLoadedData, LevelSwitchingData, + PlaylistLevelType, } from "hls.js"; import type { HlsConfig, Events } from "hls.js"; import { FragmentLoaderBase } from "./fragment-loader"; @@ -11,8 +12,6 @@ import { PlaylistLoaderBase } from "./playlist-loader"; import { SegmentManager } from "./segment-mananger"; import { Core, CoreEventHandlers } from "p2p-media-loader-core"; -const LIVE_EDGE_DELAY = 25; - export class Engine { private readonly core: Core; private readonly segmentManager: SegmentManager; @@ -24,14 +23,10 @@ export class Engine { this.segmentManager = new SegmentManager(this.core); } - public getConfig(): Pick< - HlsConfig, - "fLoader" | "pLoader" | "liveSyncDuration" - > { + public getConfig(): Partial { return { fLoader: this.createFragmentLoaderClass(), pLoader: this.createPlaylistLoaderClass(), - liveSyncDuration: LIVE_EDGE_DELAY, }; } @@ -118,6 +113,18 @@ export class Engine { event: string, data: LevelUpdatedData | AudioTrackLoadedData, ) => { + if ( + this.currentHlsInstance && + data.details.live && + data.details.fragments[0].type === ("main" as PlaylistLevelType) && + !this.currentHlsInstance.userConfig.liveSyncDuration && + !this.currentHlsInstance.userConfig.liveSyncDurationCount && + data.details.fragments.length > 4 + ) { + this.currentHlsInstance.config.liveSyncDurationCount = + data.details.fragments.length - 1; + } + this.core.setIsLive(data.details.live); this.segmentManager.updatePlaylist(data); };