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

Hello,How to customize a fLoader? #6315

Open
skerhub opened this issue Mar 27, 2024 · 2 comments
Open

Hello,How to customize a fLoader? #6315

skerhub opened this issue Mar 27, 2024 · 2 comments

Comments

@skerhub
Copy link

skerhub commented Mar 27, 2024

What do you want to do with Hls.js?

I want to customize a fLoader to handle ts slicing

What have you tried so far?

No response

@skerhub skerhub added Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. Question labels Mar 27, 2024
@skerhub
Copy link
Author

skerhub commented Mar 27, 2024

I don't understand this document how to operate

@robwalch
Copy link
Collaborator

The CMCD controller shows an example of extending the built-in Loader (XHR, Fetch, or even a custom Loader) assigned to fLoader:

config.fLoader = this.createFragmentLoader();

private createFragmentLoader(): FragmentLoaderConstructor | undefined {
const { fLoader } = this.config;
const apply = this.applyFragmentData;
const Ctor = fLoader || (this.config.loader as FragmentLoaderConstructor);
return class CmcdFragmentLoader {
private loader: Loader<FragmentLoaderContext>;
constructor(config: HlsConfig) {
this.loader = new Ctor(config);
}
get stats() {
return this.loader.stats;
}
get context() {
return this.loader.context;
}
destroy() {
this.loader.destroy();
}
abort() {
this.loader.abort();
}
load(
context: FragmentLoaderContext,
config: LoaderConfiguration,
callbacks: LoaderCallbacks<FragmentLoaderContext>,
) {
apply(context);
this.loader.load(context, config, callbacks);
}

Documentation: https://github.com/video-dev/hls.js/blob/master/docs/API.md#floader

It works by setting the player config fLoader to a class that implements Loader:

hls.js/src/types/loader.ts

Lines 144 to 165 in 0216391

export interface Loader<T extends LoaderContext> {
destroy(): void;
abort(): void;
load(
context: T,
config: LoaderConfiguration,
callbacks: LoaderCallbacks<T>,
): void;
/**
* `getCacheAge()` is called by hls.js to get the duration that a given object
* has been sitting in a cache proxy when playing live. If implemented,
* this should return a value in seconds.
*
* For HTTP based loaders, this should return the contents of the "age" header.
*
* @returns time object being lodaded
*/
getCacheAge?: () => number | null;
getResponseHeader?: (name: string) => string | null;
context: T | null;
stats: LoaderStats;
}

The two built-in classes that implement this interface are FetchLoader:

class FetchLoader implements Loader<LoaderContext> {

and XhrLoader:

class XhrLoader implements Loader<LoaderContext> {

@robwalch robwalch added answered and removed Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants