Problem/Motivation
It is currently not possible to configure an audio file using FileAudioFormatter to be muted by default.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#Attributes
Solution
This configuration currently exists in FileVideoFormatter and works properly. Since both the audio and video formatters share FileMediaFormatterBase, moving the muted setting to that class provides this option to both formatters without breaking any existing config for videos.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | interdiff_6-19.txt | 2.41 KB | elber |
| #19 | 3090641-18.patch | 6.64 KB | elber |
| #15 | 3090641-13.patch | 1.74 KB | elber |
| #14 | interdiff_3090641_6-14.txt | 2.41 KB | ankithashetty |
| #14 | 3090641-14.patch | 6.64 KB | ankithashetty |
Comments
Comment #2
jnettikComment #4
kristen polThanks for the issue and patch.
1) Patch applies cleanly to 9.1.x.
2) Changes are straightforward (code is moved to higher level).
3) I see the muted option for Audio and for Video media types. See screenshots.
4) I do not see the muted option for the other media types which is as expected.
5) When I create an Audio field and a Video field after choosing muted to enabled, the controls do show up with muted control. See screenshots.
6) After disabling the muted option in the Audio/Video settings, the fields do not show up muted by default. See screenshots.
7) I'll kick off tests for 9.1.
8) Marking for tests since they probably need to be updated. See
core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.phpfor existing Video test.9) For some reason, at least when testing on simplytest.me, the video media field thumbnail isn't showing up so that's why it's empty in the screenshots. But I was able to use the control and could hear the audio for the video and audio media fine.
Comment #5
kristen polFyi, regarding #4.9, this is due to a simplytest.me bug: #3162126: Image styles either aren't generated or can't be downloaded
Comment #6
raman.b commentedAdding test for audio attributes similar to
core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.phpComment #10
danflanagan8I think the patch looks good and it was thoroughly tested by @Kristen Pol in #4. The test added in #6 looks great (very closely modeled after an existing core test), but it uses some recently deprecated code that needs to be updated.
This needs to be replaced with:
$file_url = \Drupal::service('file_url_generator')->generateString($file->getFileUri());It should be an easy update. The patch in #6 still applies cleanly.
Comment #11
elberComment #12
elberComment #13
danflanagan8@elber, that patch was empty. Did you upload the wrong file?
Comment #14
ankithashettyHere is an updated patch, thanks!
Comment #15
elberSorry my patch is here.
Comment #17
elberComment #18
danflanagan8@ankithashetty, why does your patch include a change to
core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php? Could you explain that? It may be right, but I wasn't expecting it.@elber, your patch only contains the new test, with none of the other changes, which is why it failed. Posting an interdiff along with your patch can make it easier to review, too. Here are instructions: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
It looks like we've gotten ourselves into a situation where both of you are working at the same time. Personally, I would like to see @elber finish this off since it's really a Novice issue at this point. I'll tag it as such.
But I would still like to hear from @ankithashetty about that extra change in the patch in #14. Is that something @elber should incorporate?
Comment #19
elberComment #20
danflanagan8Something is still really fishy with this interdiff. When I diff #6 and #18, the only change I see is the line in the test. I don't see any diff in
FileMediaFormatterBase. So why is there a change shown in the interdiff? Also, I should be able to apply the interdiff as a patch on top of the patch from #6. But doing that fails. So something is wrong with the interdiff.Comment #21
danflanagan8The patch itself though looks good. Regardless of what the interdiff says, the only change is the fix to the deprecated code in the new test. I also applied the patch in #18 locally and tested it with video and audio media. The muted configuration does what is expected for video and audio media. @Kristen Pol also did thorough testing previously.
RTBC!
Even if the use cases for muting an audio field by default are rare, I think this patch does the right thing by moving that configuration to the base formatter. If that's where autoplay is, that's where muted should be.
Comment #23
danflanagan8The recent failures were random fails in Layout Builder functional javascript tests, a well known issue. Unrelated to changes here. Setting back to RTBC.
Comment #25
danflanagan8That was a random test fail in
Drupal\Tests\layout_builder\FunctionalJavascript\ContentPreviewToggleTestBack to RTBC.
Comment #27
danflanagan8Those were random fails in LAyoutBuilder functional js tests. Back to RTBC.
Comment #29
danflanagan8Unrelated fail. Back to RTBC.
Comment #30
alexpottI think we need a change record here because we are changing a base class and there are quite a few implementations in contrib. For example - https://git.drupalcode.org/project/media_entity_lottie/-/blob/2.0.x/src/... - see https://git.drupalcode.org/search?group_id=2&page=3&repository_ref=&scop... for more implementations. The CR needs to cover what is going to change for these contrib modules and what they'd need to do to opt out if the player does not support it.
Comment #31
mrshowermanWhat if we move this functionality to a new base class
FileMuteableMediaFormatterBase(not quite sure about the wording) that extendsFileMediaFormatterBase? That way, contrib modules aren't forced to opt out of this functionality, while they can opt in by simply extending the new class.We will still need a change record, though.