diff --git a/extensions/amp-story/1.0/media-pool.js b/extensions/amp-story/1.0/media-pool.js index eb3b556d554a..f5c35ab1b845 100644 --- a/extensions/amp-story/1.0/media-pool.js +++ b/extensions/amp-story/1.0/media-pool.js @@ -850,6 +850,11 @@ export class MediaPool { return Promise.resolve(); } + // When a video is muted, reset its volume to the default value of 1. + if (mediaType == MediaType.VIDEO) { + domMediaEl.volume = 1; + } + return this.enqueueMediaElementTask_(poolMediaEl, new MuteTask()); } @@ -870,6 +875,16 @@ export class MediaPool { return Promise.resolve(); } + if (mediaType == MediaType.VIDEO) { + const ampVideoEl = domMediaEl.parentElement; + if (ampVideoEl) { + const volume = ampVideoEl.getAttribute('volume'); + if (volume) { + domMediaEl.volume = parseFloat(volume); + } + } + } + return this.enqueueMediaElementTask_(poolMediaEl, new UnmuteTask()); } diff --git a/extensions/amp-story/1.0/test/validator-amp-story-video-error.html b/extensions/amp-story/1.0/test/validator-amp-story-video-error.html index 1feb36b34405..a13b0cf6980c 100644 --- a/extensions/amp-story/1.0/test/validator-amp-story-video-error.html +++ b/extensions/amp-story/1.0/test/validator-amp-story-video-error.html @@ -32,6 +32,40 @@ + + + + +
+

Your browser doesn't support HTML5 video.

+
+ + +
+
+
+ + + + +
+

Your browser doesn't support HTML5 video.

+
+ + +
+
+
diff --git a/extensions/amp-story/1.0/test/validator-amp-story-video-error.out b/extensions/amp-story/1.0/test/validator-amp-story-video-error.out index ff075aac023f..473a3a32d02e 100644 --- a/extensions/amp-story/1.0/test/validator-amp-story-video-error.out +++ b/extensions/amp-story/1.0/test/validator-amp-story-video-error.out @@ -37,6 +37,44 @@ amp-story/1.0/test/validator-amp-story-video-error.html:23:8 The mandatory attri | | | +| +| +| +| > ^~~~~~~~~ +amp-story/1.0/test/validator-amp-story-video-error.html:38:8 The attribute 'volume' in tag 'amp-video' is set to the invalid value '0'. (see https://amp.dev/documentation/components/amp-video/) +| height="270" +| poster="/foo.jpg" +| src="/video/tokyo.mp4" +| layout="responsive" +| volume="0"> +|
+|

Your browser doesn't support HTML5 video.

+|
+| +| +|
+|
+|
+| +| +| +| > ^~~~~~~~~ +amp-story/1.0/test/validator-amp-story-video-error.html:55:8 The attribute 'volume' in tag 'amp-video' is set to the invalid value '1.01'. (see https://amp.dev/documentation/components/amp-video/) +| height="270" +| poster="/foo.jpg" +| src="/video/tokyo.mp4" +| layout="responsive" +| volume="1.01"> +|
+|

Your browser doesn't support HTML5 video.

+|
+| +| +|
+|
+|
| | -| +| \ No newline at end of file diff --git a/extensions/amp-video/validator-amp-video.protoascii b/extensions/amp-video/validator-amp-video.protoascii index 2327ea1be7f8..601ebd0c61a8 100644 --- a/extensions/amp-video/validator-amp-video.protoascii +++ b/extensions/amp-video/validator-amp-video.protoascii @@ -183,6 +183,12 @@ tags: { # in amp-story name: "captions-id" requires_extension: "amp-story-captions" } + attrs: { + name: "volume" + # Disallow 0 to prevent shipping unnecessary audio track when the video is muted. + # Volume must be in the range [0.1, 1]. + value_regex: "^((0?\.[1-9]+)?|1(\.0*)?)$" + } attr_lists: "extended-amp-global" attr_lists: "amp-video-common" spec_url: "https://amp.dev/documentation/components/amp-video/"