Skip to content

Commit

Permalink
[BUGFIX] Set mute=1 if autoplay=1 for rendering youtube videos
Browse files Browse the repository at this point in the history
The option "autoplay" only works if "mute" is enabled. See
https://developer.chrome.com/blog/autoplay/ for reference.

Resolves: #96320
Releases: main, 11.5, 10.4
Change-Id: Ic4e2de0576fe3d1619af8e35274adeb013c72b31
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72621
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Daniel Haupt <mail@danielhaupt.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Daniel Haupt <mail@danielhaupt.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
georgringer authored and lolli42 committed Jan 4, 2022
1 parent 14dc3b0 commit fc31824
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -141,6 +141,8 @@ protected function createYouTubeUrl(array $options, FileInterface $file)
$urlParams[] = 'controls=' . $options['controls'];
if (!empty($options['autoplay'])) {
$urlParams[] = 'autoplay=1';
// If autoplay is enabled, enforce mute=1, see https://developer.chrome.com/blog/autoplay/
$urlParams[] = 'mute=1';
}
if (!empty($options['modestbranding'])) {
$urlParams[] = 'modestbranding=1';
Expand Down
Expand Up @@ -110,7 +110,7 @@ public function renderOutputWithAutoplayIsCorrect(): void
$fileResourceMock = $this->createMock(File::class);

self::assertSame(
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=1&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=1&amp;autoplay=1&amp;mute=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
$this->subject->render($fileResourceMock, '300m', '200', ['controls' => 1, 'autoplay' => 1])
);
}
Expand All @@ -129,7 +129,7 @@ public function renderOutputWithAutoplayFromFileReferenceIsCorrect(): void
$fileReferenceMock->method('getOriginalFile')->willReturn($fileResourceMock);

self::assertSame(
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=1&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=1&amp;autoplay=1&amp;mute=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
$this->subject->render($fileReferenceMock, '300m', '200', ['controls' => 1])
);
}
Expand All @@ -143,7 +143,7 @@ public function renderOutputWithAutoplayAndWithoutControlsIsCorrect(): void
$fileResourceMock = $this->createMock(File::class);

self::assertSame(
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=0&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=0&amp;autoplay=1&amp;mute=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
$this->subject->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1])
);
}
Expand Down Expand Up @@ -340,7 +340,7 @@ public function renderOutputWithCustomAllowAndAutoplayIsCorrect(): void
$fileResourceMock = $this->createMock(File::class);

self::assertSame(
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=0&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="foo; bar"></iframe>',
'<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&amp;controls=0&amp;autoplay=1&amp;mute=1&amp;enablejsapi=1&amp;origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="foo; bar"></iframe>',
$this->subject->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1, 'allow' => 'foo; bar'])
);
}
Expand Down

0 comments on commit fc31824

Please sign in to comment.