diff --git a/extensions/amp-brightcove/0.1/amp-brightcove.js b/extensions/amp-brightcove/0.1/amp-brightcove.js index a1369100c5b4..f79ea8cacf28 100644 --- a/extensions/amp-brightcove/0.1/amp-brightcove.js +++ b/extensions/amp-brightcove/0.1/amp-brightcove.js @@ -332,7 +332,7 @@ class AmpBrightcove extends AMP.BaseElement { `https://players.brightcove.net/${encodeURIComponent(account)}` + `/${encodeURIComponent(this.playerId_)}` + `_${encodeURIComponent(embed)}/index.html` + - '?amp=1&autoplay=false' + + '?amp=1' + // These are encodeURIComponent'd in encodeId_(). (el.getAttribute('data-playlist-id') ? '&playlistId=' + this.encodeId_(el.getAttribute('data-playlist-id')) @@ -366,6 +366,9 @@ class AmpBrightcove extends AMP.BaseElement { el.setAttribute('data-param-playsinline', 'true'); + if (el.hasAttribute('data-param-autoplay')) { + el.removeAttribute('data-param-autoplay'); + } // Pass through data-param-* attributes as params for plugin use return addParamsToUrl(src, getDataParamsFromAttributes(el)); } @@ -456,8 +459,8 @@ class AmpBrightcove extends AMP.BaseElement { } /** @override */ - play(unusedIsAutoplay) { - this.sendCommand_('play'); + play(isAutoplay) { + this.sendCommand_('play', isAutoplay); } /** @override */ diff --git a/extensions/amp-brightcove/0.1/test/test-amp-brightcove.js b/extensions/amp-brightcove/0.1/test/test-amp-brightcove.js index 338d4d1687f4..5a1beb8fb46b 100644 --- a/extensions/amp-brightcove/0.1/test/test-amp-brightcove.js +++ b/extensions/amp-brightcove/0.1/test/test-amp-brightcove.js @@ -114,7 +114,7 @@ describes.realWin( expect(iframe.tagName).to.equal('IFRAME'); expect(iframe.src).to.equal( 'https://players.brightcove.net/1290862519001/default_default' + - '/index.html?amp=1&autoplay=false' + + '/index.html?amp=1' + '&videoId=ref:amp-test-video&playsinline=true' ); }); @@ -145,6 +145,18 @@ describes.realWin( }); }); + it('should exclude data-param-autoplay attribute', () => { + return getBrightcove({ + 'data-account': '1290862519001', + 'data-video-id': 'ref:amp-test-video', + 'data-param-autoplay': 'muted', + }).then((bc) => { + const iframe = bc.querySelector('iframe'); + const params = parseUrlDeprecated(iframe.src).search.split('&'); + expect(params).to.not.contain('autoplay'); + }); + }); + it('should propagate mutated attributes', () => { return getBrightcove({ 'data-account': '1290862519001', @@ -154,7 +166,7 @@ describes.realWin( expect(iframe.src).to.equal( 'https://players.brightcove.net/1290862519001/default_default' + - '/index.html?amp=1&autoplay=false' + + '/index.html?amp=1' + '&videoId=ref:amp-test-video&playsinline=true' ); @@ -167,7 +179,7 @@ describes.realWin( expect(iframe.src).to.equal( 'https://players.brightcove.net/' + - '12345/default_default/index.html?amp=1&autoplay=false' + + '12345/default_default/index.html?amp=1' + '&videoId=abcdef&playsinline=true' ); }); @@ -325,5 +337,20 @@ describes.realWin( expect(iframe.src).to.contain('ampInitialConsentValue=abc'); }); }); + + it('should distinguish autoplay', async () => { + const bc = await getBrightcove({ + 'data-account': '1290862519001', + 'data-video-id': 'ref:amp-test-video', + }); + const impl = await bc.getImpl(); + const spy = env.sandbox.spy(impl, 'sendCommand_'); + + impl.play(true); + expect(spy).to.be.calledWith('play', true); + + impl.play(false); + expect(spy).to.be.calledWith('play', false); + }); } );