Skip to content
Prev Previous commit
Next Next commit
add srclang
  • Loading branch information
processprocess committed Mar 21, 2022
commit 1d0b0f3be5f425c4e5e9348998364c5c4efc93f1
2 changes: 2 additions & 0 deletions extensions/amp-video/0.1/test/test-video-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ describes.realWin('amp-video cached-sources', {amp: true}, (env) => {
json: () =>
Promise.resolve({
'captions_src': 'captions_src_response.vtt',
'captions_srclang': 'en-us',
'sources': [
{'url': 'video.mp4', 'bitrate_kbps': 700, 'type': 'video/mp4'},
],
Expand All @@ -517,6 +518,7 @@ describes.realWin('amp-video cached-sources', {amp: true}, (env) => {
json: () =>
Promise.resolve({
'captions_src': 'captions_src_response.vtt',
'captions_srclang': 'en-us',
'sources': [
{'url': 'video.mp4', 'bitrate_kbps': 700, 'type': 'video/mp4'},
],
Expand Down
15 changes: 10 additions & 5 deletions extensions/amp-video/0.1/video-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function fetchCachedSources(
.then((response) => {
applySourcesToVideo(videoEl, response['sources'], maxBitrate);
applyAudioInfoToVideo(videoEl, response['has_audio']);
applyCaptionsTrackToVideo(videoEl, response['captions_src']);
applyCaptionsTrackToVideo(videoEl, response);
})
.catch(() => {
// If cache fails, video should still load properly.
Expand Down Expand Up @@ -161,14 +161,19 @@ function applyAudioInfoToVideo(videoEl, hasAudio) {
* Appends captions track to video if captions url is defined and video
* element doesn't have a track child specified in the document.
* @param {!Element} videoEl
* @param {string|undefined} captionsUrl
* @param {!Object} response
*/
function applyCaptionsTrackToVideo(videoEl, captionsUrl) {
if (!captionsUrl || videoEl.querySelector('track')) {
function applyCaptionsTrackToVideo(videoEl, response) {
if (
!response['captions_src'] ||
!response['captions_srclang'] ||
videoEl.querySelector('track')
) {
return;
}
const trackEl = createElementWithAttributes(videoEl.ownerDocument, 'track', {
'src': captionsUrl,
'src': response['captions_src'],
'srclang': response['captions_srclang'],
'kind': 'captions',
});
videoEl.appendChild(trackEl);
Expand Down