Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 amp-brightcove: improve autoplay handling #34207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions extensions/amp-brightcove/0.1/amp-brightcove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -456,8 +459,8 @@ class AmpBrightcove extends AMP.BaseElement {
}

/** @override */
play(unusedIsAutoplay) {
this.sendCommand_('play');
play(isAutoplay) {
this.sendCommand_('play', isAutoplay);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own understanding: what's the downstream effect of passing isAutoplay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some integrations within the player need to distinguish an autoplay, e.g. to change params in an ad call.

}

/** @override */
Expand Down
33 changes: 30 additions & 3 deletions extensions/amp-brightcove/0.1/test/test-amp-brightcove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
Expand Down Expand Up @@ -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',
Expand All @@ -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'
);

Expand All @@ -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'
);
});
Expand Down Expand Up @@ -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);
});
}
);