Commit fc31824a authored by Georg Ringer's avatar Georg Ringer Committed by Christian Kuhn
Browse files

[BUGFIX] Set mute=1 if autoplay=1 for rendering youtube videos

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's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Daniel Haupt's avatarDaniel Haupt <mail@danielhaupt.de>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Daniel Haupt's avatarDaniel Haupt <mail@danielhaupt.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 14dc3b07
......@@ -141,6 +141,8 @@ class YouTubeRenderer implements FileRendererInterface
$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';
......
......@@ -110,7 +110,7 @@ class YouTubeRendererTest extends UnitTestCase
$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])
);
}
......@@ -129,7 +129,7 @@ class YouTubeRendererTest extends UnitTestCase
$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])
);
}
......@@ -143,7 +143,7 @@ class YouTubeRendererTest extends UnitTestCase
$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])
);
}
......@@ -340,7 +340,7 @@ class YouTubeRendererTest extends UnitTestCase
$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'])
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment