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

determine level resolution? #2497

Closed
Spongman opened this issue Jan 13, 2020 · 2 comments
Closed

determine level resolution? #2497

Spongman opened this issue Jan 13, 2020 · 2 comments

Comments

@Spongman
Copy link

I'm trying to determine the resolution of the currently playing Level, but sometimes the level object doesn't contain width or height fields. Where can I find this information?

hls.on(Hls.Events.LEVEL_SWITCHED, (evt: any, data: Hls.levelSwitchedData) => {
	const level = hls.levels[data.level];
	if (level) {
		console.log(`qualityChange ${level.width}x${level.height}`);
	}
});

results in qualityChange undefinedxundefined.

it depends on the stream, sometimes it's there, other times not.

@robwalch
Copy link
Collaborator

You can get videoWidth and videoHeight from the video tag:

> hlsjs.media.videoWidth
1280

The challenge is sometimes hls.js fires LEVEL_SWITCHED or FRAG_CHANGED right before the size of the video changes. So you're actually better off listening to video.onresize and then getting currentLevel from hlsjs.

@robwalch
Copy link
Collaborator

robwalch commented Mar 3, 2020

Marking this closed with the answer above.

Also note that width and height are populated in levels when your parent manifest contains the required RESOLUTION attribute. If you are playing a chunked playlist or missing that attribute you'll need to check the video tag.

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