diff --git a/lib/player/dash_video_source.js b/lib/player/dash_video_source.js index d3e4d8c559..45c0db2e25 100644 --- a/lib/player/dash_video_source.js +++ b/lib/player/dash_video_source.js @@ -65,14 +65,14 @@ shaka.player.DashVideoSource = /** @private {?shaka.player.DashVideoSource.ContentProtectionCallback} */ this.interpretContentProtection_ = interpretContentProtection; - /** @private {?string} */ - this.captionsUrl_ = null; + /** @private {!Array.} */ + this.captionsUrl_ = []; - /** @private {string} */ - this.captionsLang_ = ''; + /** @private {!Array.} */ + this.captionsLang_ = []; - /** @private {string} */ - this.captionsMime_ = ''; + /** @private {!Array.} */ + this.captionsMime_ = []; }; goog.inherits(shaka.player.DashVideoSource, shaka.player.StreamVideoSource); @@ -94,11 +94,11 @@ 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'. @@ -106,9 +106,9 @@ shaka.player.DashVideoSource.ContentProtectionCallback; */ 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 || ''); }; @@ -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 = diff --git a/spec/mpd_spec.js b/spec/mpd_spec.js index c321ec9641..8b2aec565f 100644 --- a/spec/mpd_spec.js +++ b/spec/mpd_spec.js @@ -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 = [ + '', + ' ', + ' ', + ''].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/'); + }); }); diff --git a/spec/player_integration.js b/spec/player_integration.js index 7b1263d087..44ab73323f 100644 --- a/spec/player_integration.js +++ b/spec/player_integration.js @@ -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() {