2

I want to know the bitrate during video playback in jwplayer 6's auto mode. When the video starts, the selected value is "Auto". But unlike other values, the "Auto" value doesn't include bitrate or other parameters.

my default parameters:

primary: "flash",
autostart:"true"

I've read this post but it didn't help me.

Someone can help me?

TylerH
  • 20,799
  • 66
  • 75
  • 101
The Goat
  • 1,080
  • 13
  • 19

1 Answers1

2

I got a demo from @EthanJWPlayer. It's very clear demo.. And i'm simplify that code.

Firstly add this method on your jwplayer functions:

var bitrateList = [],
    bandwidth = 0,
    currentBitrate =0,
    levels; 

jwplayer().setup({
....          
    events: 
        onQualityChange: function(callback) {
            levels = callback.levels;
            render();
        },

        onQualityLevels: function(callback) {
            levels = callback.levels;
            render();
        },

        onMeta: function(event) {
            if (event.metadata.bandwidth) {
                var b = event.metadata.bandwidth;
                var l = Number(event.metadata.currentLevel.substr(0, 1));
                if (b != bandwidth) {
                    bandwidth = b;
                    currentBitrate = bitrateList[l - 1];
                }
            }
        }
});

function render() {
    bitrateList = [];
    for (var i = 1; i < levels.length; i++) {
        bitrateList.push(levels[i].bitrate);
    }
}

and you can be give anywhere on your JavaScript code from "currentBitrate" variable. for example:

sendStatistics(currentBitrate);

In addition to adaptive bitrate streaming (adaptive streaming - jw player auto mode), changed every second bitrate value depending on the current bandwidth. If you want get value of the bitrate, append above code and get currentBitrate value.

TylerH
  • 20,799
  • 66
  • 75
  • 101
The Goat
  • 1,080
  • 13
  • 19
  • Thanks for sharing the code. If you want to make this work for the cases that quality level is changed manually, you need to remove 'if (b != bandwidth)'. And also note that if the first item of the quality list is 'Auto', then levels[0] doesn't have 'bitrate' property so we should not push it in bitrateList. At least this is the case for flash – vizog Jun 21 '15 at 07:57