-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Get regular playlist url properly in ha-hls-player #7417
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
Changes from 4 commits
20ba761
d5daf64
a8efd60
03d2d28
1b5ce66
0dc5640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,6 @@ class HaHLSPlayer extends LitElement { | |
|
|
||
| private async _startHls(): Promise<void> { | ||
| const videoEl = this._videoEl; | ||
| const playlist_url = this.url.replace("master_playlist", "playlist"); | ||
| const useExoPlayerPromise = this._getUseExoPlayer(); | ||
| const masterPlaylistPromise = fetch(this.url); | ||
|
|
||
|
|
@@ -126,13 +125,19 @@ class HaHLSPlayer extends LitElement { | |
| } | ||
|
|
||
| this._useExoPlayer = await useExoPlayerPromise; | ||
| let hevcRegexp: RegExp; | ||
| let masterPlaylist: string; | ||
| if (this._useExoPlayer) { | ||
| hevcRegexp = /CODECS=".*?((hev1)|(hvc1))\..*?"/; | ||
| masterPlaylist = await (await masterPlaylistPromise).text(); | ||
| const masterPlaylist = await (await masterPlaylistPromise).text(); | ||
|
|
||
| // use regular playlist instead of master playlist if possible | ||
| let playlist_url: string; | ||
| const playlistRegexp = /#EXT-X-STREAM-INF:.*?(?:CODECS=".*?(hev1|hvc1)?\..*?".*?)?(?:\n|\r\n)(.+)/g; | ||
| const match = playlistRegexp.exec(masterPlaylist); | ||
| if (match !== null && playlistRegexp.exec(masterPlaylist) === null) { | ||
| playlist_url = new URL(match[2], this.url).href; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please explain to me, and in a comment in the code, what we are doing here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I added comments to the code which should help clarify things. |
||
| } else { | ||
| playlist_url = this.url; | ||
| } | ||
| if (this._useExoPlayer && hevcRegexp!.test(masterPlaylist!)) { | ||
|
|
||
| if (this._useExoPlayer && match !== null && match[1] !== undefined) { | ||
| this._renderHLSExoPlayer(playlist_url); | ||
| } else if (hls.isSupported()) { | ||
| this._renderHLSPolyfill(videoEl, hls, playlist_url); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still is not clear what we are doing here, why do we do the regex a second time and why should it not match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second regex is to test whether there's another #EXT-X-STREAM-INF line which would mean that our master playlist has more than one stream. We should actually not encounter this case currently as we are currently only include one stream in our master playlist, but in case we change things, this safely sends the master_playlist instead of skipping to the regular playlist when there is more than one stream available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment for that, can we also give the various match part logical variable names? like:
const isHevc = match && match[1];There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a change, does that look better? I haven't had a chance to test it yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that looks better. Let me know when you tested it :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested it and seems to be working fine