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

Vidstack llhls with Preload Hint #96

Merged
merged 3 commits into from
Sep 17, 2024
Merged
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
12 changes: 12 additions & 0 deletions assets/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Socket } from "phoenix";
import { LiveSocket, type ViewHook } from "phoenix_live_view";
import topbar from "../vendor/topbar";
import { VidstackPlayer, VidstackPlayerLayout } from "vidstack/global/player";
import { isHLSProvider } from "vidstack";
import HLS from "@algora/hls.js";

// TODO: add eslint & biome
// TODO: enable strict mode
Expand Down Expand Up @@ -229,6 +231,16 @@ const Hooks = {
this.player.streamType = opts.is_live ? "ll-live:dvr" : "on-demand";
this.player.src = opts.url;

this.player.addEventListener("provider-change", (event) => {
const provider = event.detail;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting on a closed PR, but trying to understand how this works.

Since provider goes out of scope in line 241, does setting the target latency have any effect?

Maybe I'm missing something, but AFAICT, this event listener doesn't do anything.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I understand: the listener is being passed a reference to the MediaProviderAdapter which this function mutates.

if (isHLSProvider(provider)) {
provider.library = HLS;
provider.config = {
targetlatency: 6, // one segment
};
}
});

setMediaSession();

if (backdrop) {
Expand Down
1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/phoenix_live_view": "^0.18.4"
},
"dependencies": {
"@algora/hls.js": "1.0.0",
"vidstack": "^1.12.9"
}
}
7 changes: 7 additions & 0 deletions assets/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.