Skip to content

Commit

Permalink
Add quality choosing UI for ABR HLS
Browse files Browse the repository at this point in the history
  • Loading branch information
SangwonOh committed May 27, 2022
1 parent b607e49 commit f2550a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/ovenplayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ovenplayer.js.map

Large diffs are not rendered by default.

52 changes: 47 additions & 5 deletions src/js/api/provider/html5/providers/Hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
PLAYER_UNKNWON_NETWORK_ERROR,
PLAYER_BAD_REQUEST_ERROR,
PLAYER_AUTH_FAILED_ERROR,
PLAYER_NOT_ACCEPTABLE_ERROR
PLAYER_NOT_ACCEPTABLE_ERROR, STATE_PLAYING, CONTENT_LEVEL_CHANGED
} from "../../../constants";
import sizeHumanizer from "../../../../utils/sizeHumanizer";

/**
* @brief hlsjs provider extended core.
Expand Down Expand Up @@ -89,6 +90,22 @@ const HlsProvider = function (element, playerConfig, adTagUrl) {
hls.once(Hls.Events.MANIFEST_LOADED, function (event, data) {

isManifestLoaded = true;

for(let i = 0; i < hls.levels.length; i ++) {

let qualityLevel = hls.levels[i];

spec.qualityLevels.push({
bitrate: qualityLevel.bitrate,
height: qualityLevel.height,
width: qualityLevel.width,
index: i,
label: qualityLevel.width + "x" + qualityLevel.height + ", " + sizeHumanizer(qualityLevel.bitrate, true, "bps")
});
}

spec.currentQuality = hls.firstLevel;

});

hls.once(Hls.Events.LEVEL_LOADED, function (event, data) {
Expand All @@ -110,6 +127,17 @@ const HlsProvider = function (element, playerConfig, adTagUrl) {
}
});

hls.on(Hls.Events.LEVEL_SWITCHED , function (event, data) {

spec.currentQuality = data.level;

that.trigger(CONTENT_LEVEL_CHANGED, {
isAuto: hls.autoLevelEnabled,
currentQuality: spec.currentQuality,
type: "render"
});
});

hls.on(Hls.Events.ERROR, function (event, data) {

if (data && data.networkDetails && data.networkDetails.status === 202) {
Expand Down Expand Up @@ -172,11 +200,23 @@ const HlsProvider = function (element, playerConfig, adTagUrl) {
});
});

superDestroy_func = that.super('destroy');
OvenPlayerConsole.log("HLS PROVIDER LOADED.");
that.setCurrentQuality = (qualityIndex) => {

superStop_func = that.super('stop');
hls.currentLevel = qualityIndex;
spec.currentQuality = qualityIndex;

return spec.currentQuality;
};

that.isAutoQuality = () => {
return hls.autoLevelEnabled;
};

that.setAutoQuality = (isAuto) => {
hls.currentLevel = -1;
};

superStop_func = that.super('stop');
that.stop = () => {

if (loadRetryer) {
Expand All @@ -192,6 +232,7 @@ const HlsProvider = function (element, playerConfig, adTagUrl) {
superStop_func();
};

superDestroy_func = that.super('destroy');
that.destroy = () => {

if (loadRetryer) {
Expand All @@ -203,14 +244,15 @@ const HlsProvider = function (element, playerConfig, adTagUrl) {
if (hls) {

hls.destroy();

that.trigger(HLS_DESTROYED);
}

hls = null;
OvenPlayerConsole.log("HLS : PROVIDER DESTROUYED.");
superDestroy_func();
};

OvenPlayerConsole.log("HLS PROVIDER LOADED.");
} catch (error) {
let tempError = ERRORS.codes[INIT_HLSJS_FAIL];
tempError.error = error;
Expand Down

3 comments on commit f2550a8

@genofire
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ui, when we get it on Engine site?

AirenSoft/OvenMediaEngine#132

@SangwonOh
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@genofire
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Please sign in to comment.