Information with Listeners and Method Calls

Use event listeners and Player V4 API methods to retrieve the asset's information you want to work with.

The simplistic example here uses getter methods to retrieve the asset's basic information (title, description, and duration) and bitrate- and buffer-related details. There are many other events and methods available.

In addition, the basic structure of an event listener is shown here, using mb.subscribe.

 
.
.
.
  // Buffer listener
  // Need to subscribe to an event if you want updates for the length of the buffer.
  // Ideally you'd listen for the BUFFERING event.
  window.bufferLength = -100;
  player.subscribe('playheadTimeChanged', 'myPage', function(eventName) {
    var newBufferLength = player.getBufferLength();
    if (bufferLength === newBufferLength) { return; }
    window.bufferElement.innerHTML += "Buffer length is " + player.getBufferLength() + "<br/>"
    window.bufferLength = newBufferLength;
  });

  // Bitrate listener
  // You *must* listen to bitrateInfoAvailable in order to request it.
  player.subscribe('bitrateInfoAvailable', 'myPage', function(eventName) {
    var rates = player.getBitratesAvailable();
    if (rates.length > 0) {
      for (var i=0; i < rates.length; i++) {
        window.bitrateElement.innerHTML += "Rate: " + rates[i] + "<br/>"
      }
    }
  });

  // Metadata
  // Content information is available after contentTreeFetched, but it is best to wait until
  // playbackReady for duration.
  player.subscribe('playbackReady', 'myPage', function(eventName) {
    window.metadataElement.innerHTML += "Title is: " + player.getTitle() + "<br/>";
    window.metadataElement.innerHTML += "Description is: " + player.getDescription() + "<br/>";
    window.metadataElement.innerHTML += "Duration is: " + player.getDuration() + "<br/>";
  });
}

window.bufferElement = getElement('buffer');
window.bitrateElement = getElement('bitrate');
window.metadataElement = getElement('metadata');
.
.
.
 

해당 내용이 도움 되었습니까?