Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To analyze the code, let's take the version of file hls-player.js with hash c306c1bbf49bfcbd8e24be927ae95f63b7dbaaba66cc393, which is available here and  and can be downloaded with corresponding build 0.5.28.2753.2747133.

1. Forming HLS server URL.

getHLSUrl() code

Code Block
languagejs
themeRDark
function initPage() {
    $("#urlServer").val(getHLSUrl());

    ...
}

2. Player initializing

videojs() code

<div>-element name to play the stream passed to the player

...

3. Stream name definition (the stream must be published on server)

encodeURIComponent() code

Code Block
languagejs
themeRDark
function initPage() {
    ...
    var applyFn = function () {
        var streamName = $("#playStream").val();
        streamName = encodeURIComponent(streamName);
        ...
    };
    ...
}

4. Forming HLS stream URL and player starting

player.play() 

code

Code Block
languagejs
themeRDark
function initPage() {
    ...
    var applyFn = function () {
        ...
        var src  player.src({
  = $("#urlServer").val() + "/" + streamName + "/" + streamName + ".m3u8";
        var key = $('#key').val();
        var token src:= $("#urlServer#token").val();
        if (key.length > 0 && token.length > 0) {
            src += "/?" + streamNamekey + "/=" + streamName + ".m3u8" token;
        }
        player.src({
            src: src,
            type: "application/vnd.apple.mpegurl"
        });
        player.play();
    };
    $("#applyBtn").prop('disabled', false).click(applyFn);

}