-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Description
Description
When publishers are opted-in for a video cache (amp-video[cache=*]
), a XHR is sent to the cache provider, and the XHR response is the buildCallback
's response.
If that XHR fails (non 20x HTTP codes), the buildCallback fails, and the video playback fails. That is wrong, and we should use the origin sources for video playback.
Relevant code pointers:
amphtml/extensions/amp-video/0.1/amp-video.js
Line 271 in 172a408
return fetchCachedSources( |
amphtml/extensions/amp-video/0.1/video-cache.js
Lines 22 to 63 in 172a408
export function fetchCachedSources( | |
videoEl, | |
ampdoc, | |
maxBitrate = Number.POSITIVE_INFINITY | |
) { | |
const {win} = ampdoc; | |
// Keep non cached evergreen sources for crawlers. | |
if (Services.platformFor(win).isBot()) { | |
return Promise.resolve(); | |
} | |
if ( | |
!( | |
videoEl.getAttribute('src') || | |
videoEl.querySelector('source[src]')?.getAttribute('src') | |
) | |
) { | |
user().error('AMP-VIDEO', 'Video cache not properly configured'); | |
return Promise.resolve(); | |
} | |
Services.performanceFor(ampdoc.win).addEnabledExperiment('video-cache'); | |
const {canonicalUrl, sourceUrl} = Services.documentInfoForDoc(win.document); | |
maybeReplaceSrcWithSourceElement(videoEl, win); | |
const videoUrl = resolveRelativeUrl(selectVideoSource(videoEl), sourceUrl); | |
return getCacheUrlService(videoEl, ampdoc) | |
.then((service) => service.createCacheUrl(videoUrl)) | |
.then((cacheUrl) => { | |
const requestUrl = addParamsToUrl(cacheUrl.replace(/\/[ic]\//, '/mbv/'), { | |
'amp_video_host_url': | |
/* document url that contains the video */ canonicalUrl, | |
}); | |
return Services.xhrFor(win).fetch(requestUrl, {prerenderSafe: true}); | |
}) | |
.then((response) => response.json()) | |
.then((jsonResponse) => | |
applySourcesToVideo(videoEl, jsonResponse['sources'], maxBitrate) | |
) | |
.catch(() => { | |
// If cache fails, video should still load properly. | |
}); | |
} |
Ensuring that fetchCachedSources
always resolve, either from amp-video or from video-cache, should work just fine.
Reproduction Steps
Relevant Logs
No response
Browser(s) Affected
No response
OS(s) Affected
No response
Device(s) Affected
No response
AMP Version Affected
No response