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

[shaka] Preload shaka media #37

Open
austinh opened this issue Sep 19, 2024 · 3 comments
Open

[shaka] Preload shaka media #37

austinh opened this issue Sep 19, 2024 · 3 comments

Comments

@austinh
Copy link

austinh commented Sep 19, 2024

Hello, i have an app with a grid of videos and I would like to preload them as the user scrolls, and stop loading them as the user scrolls past them (user unlikely to play those they scroll past).

shaka player provides a preload api to prefrtch the manifest and the first segment, as well as destroy/stop preloads midflight. Does this library expose any way for the media elements to preload things, or at least have access to the underlying instance? Would be nice to customize some of the initialization options too

hls.js also has a loadSource function, can I utilize that with hls-video element?

if not, how do you recommend someone preload something (ideally from a cache)

@luwes
Copy link
Collaborator

luwes commented Sep 19, 2024

Hi, thanks for bringing this up.

hls-video has this preload function built in as you can see here
https://github.com/muxinc/media-elements/blob/main/packages/hls-video-element/hls-video-element.js#L51-L87

The preload attribute / property together with the load() method should offer what you are looking for.

For shaka-video we haven't implemented preload it seems so I'll leave this issue open to track it.
If you feel up for it happy to review a PR for this addition.

@luwes luwes added the enhancement New feature or request label Sep 19, 2024
@luwes luwes changed the title Preload shaka media [shaka] Preload shaka media Sep 19, 2024
@austinh
Copy link
Author

austinh commented Sep 19, 2024

Thanks for your response. Unfortunately that does not allow preloading off screen (before a video element has been initialized) . This is normally accomplished by calling an imperative function during some sort of user intent, but the media may not be attached yet. Is that something the hls player element allows access to?

@luwes
Copy link
Collaborator

luwes commented Sep 19, 2024

yes, you can create and upgrade the element before attaching to the document.

since it's a custom element you'd have to use
https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/upgrade

example:
https://codesandbox.io/p/sandbox/hls-video-preload-x8wg2l?file=%2Findex.html%3A37%2C16

@luwes luwes removed the enhancement New feature or request label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants