Skip to content

Commit

Permalink
addExternalCaptions can now be called more than once.
Browse files Browse the repository at this point in the history
Multiple calls to DashVideoSource.addExternalCaptions will each
add a caption source to the object.  Added unit and integration
tests for this.

Change-Id: I387d285b5d11aa345b3abefab05d633194863030
  • Loading branch information
TheModMaker committed Jul 30, 2015
1 parent 2448715 commit 950b173
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/player/dash_video_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ shaka.player.DashVideoSource =
/** @private {?shaka.player.DashVideoSource.ContentProtectionCallback} */
this.interpretContentProtection_ = interpretContentProtection;

/** @private {?string} */
this.captionsUrl_ = null;
/** @private {!Array.<string>} */
this.captionsUrl_ = [];

/** @private {string} */
this.captionsLang_ = '';
/** @private {!Array.<string>} */
this.captionsLang_ = [];

/** @private {string} */
this.captionsMime_ = '';
/** @private {!Array.<string>} */
this.captionsMime_ = [];
};
goog.inherits(shaka.player.DashVideoSource, shaka.player.StreamVideoSource);

Expand All @@ -94,21 +94,21 @@ shaka.player.DashVideoSource.ContentProtectionCallback;


/**
* Uses the given URL as a source for text tracks in addition to those
* Adds the given URL as a source for text tracks in addition to those
* specified in the MPD. This has no effect after load().
*
* @param {string} url The |url| of the file to load from.
* @param {string=} opt_lang Optional language of the text tracks,
* @param {string=} opt_lang Optional language of the text track,
* defaults to 'en'.
* @param {string=} opt_mime Optional MIME type of the file, defaults
* to 'text/vtt'.
* @export
*/
shaka.player.DashVideoSource.prototype.addExternalCaptions =
function(url, opt_lang, opt_mime) {
this.captionsUrl_ = url;
this.captionsLang_ = opt_lang || '';
this.captionsMime_ = opt_mime || '';
this.captionsUrl_.push(url);
this.captionsLang_.push(opt_lang || '');
this.captionsMime_.push(opt_mime || '');
};


Expand All @@ -125,9 +125,9 @@ shaka.player.DashVideoSource.prototype.load = function(preferredLanguage) {
return mpdRequest.send().then(shaka.util.TypedBind(this,
/** @param {!shaka.dash.mpd.Mpd} mpd */
function(mpd) {
if (!!this.captionsUrl_) {
mpd.addExternalCaptions(this.captionsUrl_,
this.captionsLang_, this.captionsMime_);
for (var i = 0; i < this.captionsUrl_.length; i++) {
mpd.addExternalCaptions(this.captionsUrl_[i],
this.captionsLang_[i], this.captionsMime_[i]);
}

var mpdProcessor =
Expand Down
31 changes: 31 additions & 0 deletions spec/mpd_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,35 @@ describe('mpd', function() {
var representation = adaptationSet.representations[0];
expect(representation.baseUrl.toString()).toBe('http://example.com/');
});

it('handles adding multiple external captions', function() {
var source = [
'<MPD>',
' <Period id="1" duration="PT0H1M0.00S">',
' </Period>',
'</MPD>'].join('\n');

var mpd = shaka.dash.mpd.parseMpd(source, '');
mpd.addExternalCaptions('http://example.com/');
mpd.addExternalCaptions('http://example.com/', 'es');

var period = mpd.periods[0];
expect(period.adaptationSets.length).toBe(2);

var adaptationSet = period.adaptationSets[0];
expect(adaptationSet.contentType).toBe('text');
expect(adaptationSet.lang).toBe('en');
expect(adaptationSet.representations.length).toBe(1);

var representation = adaptationSet.representations[0];
expect(representation.baseUrl.toString()).toBe('http://example.com/');

var adaptationSet2 = period.adaptationSets[1];
expect(adaptationSet2.contentType).toBe('text');
expect(adaptationSet2.lang).toBe('es');
expect(adaptationSet2.representations.length).toBe(1);

var representation2 = adaptationSet2.representations[0];
expect(representation.baseUrl.toString()).toBe('http://example.com/');
});
});
15 changes: 15 additions & 0 deletions spec/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,21 @@ describe('Player', function() {
done();
});
});

it('can be called multiple times', function(done) {
var source = newSource(plainManifest);
source.addExternalCaptions(captionFile);
source.addExternalCaptions(captionFile, 'es');

player.load(source).then(function() {
var tracks = player.getTextTracks();
expect(tracks.length).toBe(2);
done();
}).catch(function(error) {
fail(error);
done();
});
});
});

describe('enableTextTrack', function() {
Expand Down

0 comments on commit 950b173

Please sign in to comment.