Skip to content

Commit

Permalink
Add Streaming Event and Manifest Getter Method
Browse files Browse the repository at this point in the history
Adding an event right after the player parses the manifest, and before
initiating streaming, so that users can get the manifest information.
Adding manifest getter method in player so that customers can access
manifest information.

Closes #1043
Closes #1074
Issue #1036

Change-Id: I0016c312bacdfa86299e5df68b586f90d565cfdc
  • Loading branch information
michellezhuogg committed Oct 26, 2017
1 parent 113d974 commit bd37a7c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cast/cast_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ shaka.cast.CastUtils.PlayerEvents = [
'emsg',
'error',
'loading',
'unloading',
'streaming',
'texttrackvisibility',
'timelineregionadded',
'timelineregionenter',
'timelineregionexit',
'trackschanged'
'trackschanged',
'unloading'
];


Expand All @@ -114,6 +115,7 @@ shaka.cast.CastUtils.PlayerGetterMethods = [
'getBufferedInfo',
'getConfiguration',
'getExpiration',
'getManifest',
'getManifestUri',
'getPlaybackRate',
'getTextLanguages',
Expand Down
25 changes: 25 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ shaka.Player.version = GIT_VERSION;
*/


/**
* @event shaka.Player.StreamingEvent
* @description Fired after the manifest has been parsed and track information
* is available, but before streams have been chosen and before any segments
* have been fetched. You may use this event to configure the player based on
* information found in the manifest.
* @property {string} type
* 'streaming'
* @exportDoc
*/


/** @private {!Object.<string, function():*>} */
shaka.Player.supportPlugins_ = {};

Expand Down Expand Up @@ -646,6 +658,9 @@ shaka.Player.prototype.load = function(manifestUri, opt_startTime,
this.streamingEngine_ = this.createStreamingEngine();
this.streamingEngine_.configure(this.config_.streaming);

var event = new shaka.util.FakeEvent('streaming');
this.dispatchEvent(event);

// If the content is multi-codec and the browser can play more than one of
// them, choose codecs now before we initialize streaming.
this.chooseCodecsAndFilterManifest_();
Expand Down Expand Up @@ -1744,6 +1759,16 @@ shaka.Player.prototype.retryStreaming = function() {
};


/**
* Return the manifest information if it's loaded. Otherwise, return null.
* @return {?shakaExtern.Manifest}
* @export
*/
shaka.Player.prototype.getManifest = function() {
return this.manifest_;
};


/**
* Initialize the Player.
* @private
Expand Down
19 changes: 19 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,25 @@ describe('Player', function() {
player.unload().catch(fail);
});

it('streaming event', function(done) {
var streamingListener = jasmine.createSpy('listener');
streamingListener.and.callFake(function() {
var tracks = player.getVariantTracks();
expect(tracks).toBeDefined();
expect(tracks.length).toEqual(1);
var activeTracks = player.getVariantTracks().filter(function(track) {
return track.active;
});
expect(activeTracks.length).toEqual(0);
});

player.addEventListener('streaming', Util.spyFunc(streamingListener));
expect(streamingListener).not.toHaveBeenCalled();
player.load('', 0, factory1).then(function() {
expect(streamingListener).toHaveBeenCalled();
}).catch(fail).then(done);
});

describe('interruption during', function() {
beforeEach(function() {
checkError.and.callFake(function(error) {
Expand Down

0 comments on commit bd37a7c

Please sign in to comment.