-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Problems in a Capacitor app using CapacitorHttp plugin #6755
Comments
HLS.js uses the response URL as the base URL when resolving relative URLs in HLS playlists: The base for media playlists is the response URL from the parent multi-variant playlist: hls.js/src/loader/playlist-loader.ts Lines 363 to 365 in bf0180c
The base for media segments is the response URL from the parent media playlist: hls.js/src/loader/playlist-loader.ts Lines 454 to 463 in bf0180c
This is the method that gets the response URL. There is no way to currently override it. We could accept a PR that adds an option to do this. The alternative would be to customize the loader so that you rewrite the response URL to match the context URL on complete. hls.js/src/loader/playlist-loader.ts Lines 51 to 62 in bf0180c
The issue is that segment URLs in the media playlist are relative to their parent media playlist, not the multi-variant playlist. |
Thank you very much @robwalch. Based on your suggestion:
I made a custom loader that replaces the class ResponseUrlFixLoader extends Hls.DefaultConfig.loader {
load(context, config, callbacks) {
const originalSuccess = callbacks.onSuccess;
callbacks.onSuccess = (response, stats, context, networkDetails) => {
response.url = context.url;
originalSuccess(response, stats, context, networkDetails);
};
super.load(context, config, callbacks);
}
}
const hls = new Hls({
loader: ResponseUrlFixLoader
}); And now the video plays! I hope it is usefull for someone else. But I have found a new problem. I don't know if it's related to the fact of executing hls.js in a webview... or it might be related to other issue I should open. The video plays well for 3 seconds but, after that, the video does like a zoom and only a top left region is shown (the red border belongs to the video tag): What could be happening? Edit: I was testing in an Android Emulator. I have tested the same in a real device and there it works! Maybe an issue related with the emulator hardware acceleration? |
Have you looked at the page layout? An HTMLMediaElement will resize according to the resolution of rendered bitrate variants, unless it and its parent containers are constrained using CSS. |
What do you want to do with Hls.js?
I'm developing an Android hybrid application with Capacitor and using hls.js to play video sources. The application uses CapacitorHttp plugin, which patches
fetch
andXMLHttpRequest
to proxy the webview request to make with the native system. When a video is played, it fails due m3u8 and ts files failed requests.I'm trying to play the Big Buck Bunny video: https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
What have you tried so far?
In my desktop in Google Chrome browser (normal execution), the request are:
When execute that code in the Android device, the first request to the m3u8 file is made successfully. The webview makes a local request which proxies to a native system HTTP request:
The problem is that the following request hls.js does is:
note that the query param refers to
https://localhost/
(insead ofhttps://test-streams.mux.dev/x36xhzz/
, which should be the valid one).I was able to fix it manipulating the url before the request is made (I let in comments the first url modifications to clarify):
The video plays are first, but a few seconds later it ends showing weird frames.
I understand hls.js makes the requests 'based' on the first one, which was to
https://localhost/
. Is there any way to prevent this behaviour? are there any option to set that base url manually or similar...?The text was updated successfully, but these errors were encountered: