[英]How to use dynamic sources for a video in an AMP page?
I'm creating an AMP version of video pages on my VOD website.我正在我的 VOD 网站上创建 AMP 版本的视频页面。 I'm using
amp-access
to authenticate the user, and then amp-subscriptions
to check if a user has purchased access to the video.我使用
amp-access
对用户进行身份验证,然后使用amp-subscriptions
检查用户是否购买了视频访问权。 This works fine.这工作正常。 However, what I am having difficulty with is, how to dynamically set the
source
elements for the video itself.但是,我遇到的困难是如何为视频本身动态设置
source
元素。
As these videos are premium videos, I don't want the source URLs in the mark-up on page load.由于这些视频是高级视频,我不希望页面加载时标记中的源 URL。 What I would like to happen is: if a user has purchased access, to dynamically add
<source>
child elements to my amp-video
tag.我想要发生的是:如果用户购买了访问权限,则将
<source>
子元素动态添加到我的amp-video
标签。
I've tried using amp-list
and fetching the source URLs like this:我尝试使用
amp-list
并像这样获取源 URL:
<amp-list layout="nodisplay" src="/amp/encodings.json">
<template type="amp-mustache">
<source src="{{url}}" />
</template>
</amp-list>
But this seems to throw the following error in the browser console:但这似乎在浏览器控制台中引发了以下错误:
AMP validation had errors: http://example.com/video.amp.html:295:48 The parent tag of tag 'picture > source' is 'template', but it can only be 'picture'.
AMP 验证出现错误: http://example.com/video.amp.html:295:48标签“图片 > 来源”的父标签是“模板”,但只能是“图片”。 (see https://amp.dev/documentation/components/amp-img )
(见https://amp.dev/documentation/components/amp-img )
So now I'm at a loss.所以现在我很茫然。
Does any one have any ideas how I could dynamically set the source URLs for a video after authorisation?有没有人知道如何在授权后动态设置视频的源 URL?
I am not sure exactly what you looking for but i can suggest you to use amp-iframe here.我不确定您到底在寻找什么,但我可以建议您在这里使用 amp-iframe。 You can load your video content over separate page and load it though amp-iframe over web page.
您可以在单独的页面上加载您的视频内容,并通过 web 页面上的 amp-iframe 加载它。
By this approach you can add all your related scripts/styles inside iframe loaded page without any restrictions.通过这种方法,您可以在 iframe 加载页面中添加所有相关脚本/样式,而不受任何限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.