From 8c8cc091332dffc55511529e8c0c866966a5f02e Mon Sep 17 00:00:00 2001 From: Georg Ringer <georg.ringer@gmail.com> Date: Fri, 10 Dec 2021 14:06:59 +0100 Subject: [PATCH] [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/+/72846 Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../core/Classes/Resource/Rendering/YouTubeRenderer.php | 2 ++ .../Tests/Unit/Resource/Rendering/YouTubeRendererTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php index 194e908ce856..08e6b49e7c11 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php @@ -142,6 +142,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'; diff --git a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php index 84695c56b88d..863672723576 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php @@ -109,7 +109,7 @@ class YouTubeRendererTest extends UnitTestCase $fileResourceMock = $this->createMock(File::class); self::assertSame( - '<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&controls=1&autoplay=1&enablejsapi=1&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&controls=1&autoplay=1&mute=1&enablejsapi=1&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]) ); } @@ -128,7 +128,7 @@ class YouTubeRendererTest extends UnitTestCase $fileReferenceMock->expects(self::any())->method('getOriginalFile')->willReturn($fileResourceMock); self::assertSame( - '<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&controls=1&autoplay=1&enablejsapi=1&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&controls=1&autoplay=1&mute=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>', $this->subject->render($fileReferenceMock, '300m', '200', ['controls' => 1]) ); } @@ -142,7 +142,7 @@ class YouTubeRendererTest extends UnitTestCase $fileResourceMock = $this->createMock(File::class); self::assertSame( - '<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&controls=0&autoplay=1&enablejsapi=1&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&controls=0&autoplay=1&mute=1&enablejsapi=1&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]) ); } @@ -339,7 +339,7 @@ class YouTubeRendererTest extends UnitTestCase $fileResourceMock = $this->createMock(File::class); self::assertSame( - '<iframe src="https://www.youtube-nocookie.com/embed/7331?autohide=1&controls=0&autoplay=1&enablejsapi=1&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&controls=0&autoplay=1&mute=1&enablejsapi=1&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']) ); } -- GitLab