简体   繁体   English

如何在 AMP 页面中为视频使用动态源?

[英]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.

相关问题 如何使AMP视频成为整页背景? - How to make AMP-video a full page background? 在amp-story中使用amp-video时,AMP如何确定加载视频的时间? - How does AMP determine the time to load the video when using amp-video in amp-story? 即使我不使用amp-carousel,我也可以在amp-story中将amp-video-container与amp-video一起使用吗? amp-video-container做什么? - Can I use amp-video-container with amp-video in amp-story even if I am not using amp-carousel? What does amp-video-container do? 如何启用amp-ima-video - How enable amp-ima-video 当两个源都可用时,VideoJS 如何确定何时使用 HLS 与 MP4 视频? - How does VideoJS determine when to use HLS vs MP4 video when both sources are available? 什么时候应该在amp-story中的amp-video上使用layout =“ fill”与layout =“ response”? 两者有什么区别? - When should you use layout=“fill” versus layout=“responsive” on amp-video in amp-story? What is the difference between the two? Javascript添加了2个视频源 - Javascript adding 2 video sources 如何使用JavaScript动态更改多个视频源? - How do I dynamically change multiple video sources using JavaScript? 如何正确支持html5 <video> 码头来源 - How to correctly support html5 <video> sources with jetty 我如何为我的javascript代码添加更多视频源? - how would i add more video sources to my javascript code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM