Skip to content

Commit e5e2870

Browse files
author
Shaka Player BuildBot
committed
Merge remote-tracking branch 'github/master' into HEAD
2 parents 5bfa771 + ca299b2 commit e5e2870

File tree

6 files changed

+123
-15
lines changed

6 files changed

+123
-15
lines changed

build/types/polyfill

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
+../../lib/polyfill/patchedmediakeys_webkit.js
1010
+../../lib/polyfill/promise.js
1111
+../../lib/polyfill/videoplaybackquality.js
12+
+../../lib/polyfill/vttcue.js

lib/media/text_engine.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,10 @@ shaka.media.TextEngine.makeCue = function(startTime, endTime, payload) {
117117
return null;
118118
}
119119

120-
return new shaka.media.TextEngine.CueConstructor(
121-
startTime, endTime, payload);
120+
return new VTTCue(startTime, endTime, payload);
122121
};
123122

124123

125-
/** @type {function(new:TextTrackCue, number, number, string)} */
126-
shaka.media.TextEngine.CueConstructor = window.VTTCue || window.TextTrackCue;
127-
128-
129124
/** @override */
130125
shaka.media.TextEngine.prototype.destroy = function() {
131126
if (this.track_) {

lib/polyfill/vttcue.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license
3+
* Copyright 2016 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
goog.provide('shaka.polyfill.VTTCue');
19+
20+
goog.require('shaka.log');
21+
goog.require('shaka.polyfill.register');
22+
23+
24+
/**
25+
* @namespace shaka.polyfill.VTTCue
26+
*
27+
* @summary A polyfill to provide VTTCue.
28+
*/
29+
30+
31+
/**
32+
* Install the polyfill if needed.
33+
*/
34+
shaka.polyfill.VTTCue.install = function() {
35+
if (window.VTTCue) {
36+
shaka.log.info('Using native VTTCue.');
37+
return;
38+
}
39+
40+
if (!window.TextTrackCue) {
41+
shaka.log.error('VTTCue not available.');
42+
return;
43+
}
44+
45+
var constructorLength = TextTrackCue.length;
46+
if (constructorLength == 3) {
47+
shaka.log.info('Using VTTCue polyfill from 3 argument TextTrackCue.');
48+
window.VTTCue = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
49+
} else if (constructorLength == 6) {
50+
shaka.log.info('Using VTTCue polyfill from 6 argument TextTrackCue.');
51+
window.VTTCue = shaka.polyfill.VTTCue.from6ArgsTextTrackCue_;
52+
} else if (shaka.polyfill.VTTCue.canUse3ArgsTextTrackCue_()) {
53+
shaka.log.info('Using VTTCue polyfill from 3 argument TextTrackCue.');
54+
window.VTTCue = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
55+
}
56+
};
57+
58+
59+
/**
60+
* Draft spec TextTrackCue with 3 constructor arguments.
61+
* See {@link https://goo.gl/ZXBWZi W3C Working Draft 25 October 2012}.
62+
*
63+
* @param {number} startTime
64+
* @param {number} endTime
65+
* @param {string} text
66+
* @return {TextTrackCue}
67+
* @private
68+
*/
69+
shaka.polyfill.VTTCue.from3ArgsTextTrackCue_ = function(startTime, endTime,
70+
text) {
71+
return new window.TextTrackCue(startTime, endTime, text);
72+
};
73+
74+
75+
/**
76+
* Draft spec TextTrackCue with 6 constructor arguments (5th & 6th are
77+
* optional).
78+
* See {@link https://goo.gl/AYFqUh W3C Working Draft 29 March 2012}.
79+
* Quoting the access to the TextTrackCue object to avoid the compiler
80+
* complaining.
81+
*
82+
* @param {number} startTime
83+
* @param {number} endTime
84+
* @param {string} text
85+
* @return {TextTrackCue}
86+
* @private
87+
*/
88+
shaka.polyfill.VTTCue.from6ArgsTextTrackCue_ = function(startTime, endTime,
89+
text) {
90+
var id = startTime + '-' + endTime + '-' + text;
91+
return new window['TextTrackCue'](id, startTime, endTime, text);
92+
};
93+
94+
95+
/**
96+
* IE10, IE11 and Edge returns TextTrackCue.length = 0 although it accepts 3
97+
* constructor arguments.
98+
*
99+
* @return {boolean}
100+
* @private
101+
*/
102+
shaka.polyfill.VTTCue.canUse3ArgsTextTrackCue_ = function() {
103+
try {
104+
return !!shaka.polyfill.VTTCue.from3ArgsTextTrackCue_(1, 2, '');
105+
} catch (error) {
106+
return false;
107+
}
108+
};
109+
110+
111+
shaka.polyfill.register(shaka.polyfill.VTTCue.install);

shaka-player.uncompiled.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ goog.require('shaka.polyfill.MediaKeys');
4747
goog.require('shaka.polyfill.MediaSource');
4848
goog.require('shaka.polyfill.Promise');
4949
goog.require('shaka.polyfill.VideoPlaybackQuality');
50+
goog.require('shaka.polyfill.VTTCue');
5051
goog.require('shaka.polyfill.installAll');
5152
goog.require('shaka.util.Error');

test/media/ttml_text_parser_unit.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
*/
1717

1818
describe('TtmlTextParser', function() {
19-
var originalCueConstructor;
19+
var originalVTTCue;
2020

2121
beforeAll(function() {
22-
originalCueConstructor = shaka.media.TextEngine.CueConstructor;
22+
originalVTTCue = window.VTTCue;
2323
});
2424

2525
afterAll(function() {
26-
shaka.media.TextEngine.CueConstructor = originalCueConstructor;
26+
window.VTTCue = originalVTTCue;
2727
});
2828

2929
beforeEach(function() {
30-
shaka.media.TextEngine.CueConstructor = function(start, end, text) {
30+
window.VTTCue = function(start, end, text) {
3131
this.startTime = start;
3232
this.endTime = end;
3333
this.text = text;
@@ -427,7 +427,7 @@ describe('TtmlTextParser', function() {
427427

428428
it('uses a workaround for browsers not supporting align=center', function() {
429429

430-
shaka.media.TextEngine.CueConstructor = function(start, end, text) {
430+
window.VTTCue = function(start, end, text) {
431431
var align = 'middle';
432432
Object.defineProperty(this, 'align', {
433433
get: function() { return align; },

test/media/vtt_text_parser_unit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717

1818
describe('VttTextParser', function() {
1919
var logWarningSpy;
20-
var originalCueConstructor;
20+
var originalVTTCue;
2121

2222
beforeAll(function() {
23-
originalCueConstructor = shaka.media.TextEngine.CueConstructor;
23+
originalVTTCue = window.VTTCue;
2424

2525
logWarningSpy = jasmine.createSpy('shaka.log.warning');
2626
shaka.log.warning = logWarningSpy;
2727
});
2828

2929
afterAll(function() {
30-
shaka.media.TextEngine.CueConstructor = originalCueConstructor;
30+
window.VTTCue = originalVTTCue;
3131
});
3232

3333
beforeEach(function() {
3434
logWarningSpy.calls.reset();
35-
shaka.media.TextEngine.CueConstructor = function(start, end, text) {
35+
window.VTTCue = function(start, end, text) {
3636
this.startTime = start;
3737
this.endTime = end;
3838
this.text = text;

0 commit comments

Comments
 (0)