Problem/Motivation

When attempting to autoplay a current live YouTube stream, no video is displayed.

Steps to reproduce

Attempt to autoplay a current live YouTube stream

Proposed resolution

The issue appears to be related to updates in how browsers autoplay videos. Browsers mute regular HTML 5 videos that autoplay. But it seems that in order to comply with that behavior, YouTube requires you to explicitly mute the video in the oembed URL.

Remaining tasks

Review issue fork pull request.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pianomansam created an issue. See original summary.

pianomansam’s picture

Issue summary: View changes
Status: Active » Needs review

nsciacca made their first commit to this issue’s fork.

nsciacca’s picture

Thanks for this! I added a couple other parameters for YouTube when it's used as background image to suppress the controls, set the loop and a playlist param so it continues to play.

nsciacca’s picture

Patch attached.

nsciacca’s picture

StatusFileSize
new1.27 KB

Fixed patch.

le72’s picture

Applied the patch, but the background YouTube video is still not autoplay :-(
Using Drupal core 10.2.3 with Media oEmbed Control 2.0.0-beta3.

le72’s picture

The problem is in HTML::load(), HTML::saveHTML().
The "allowfullscreen" attribute becomes allowfullscreen="" and farther replacement doesn't work.

ipitbiz’s picture

StatusFileSize
new1.69 KB

I've added a small change to make the patch work, although I'd like to have it reviewed in case anyone has a better solution.

phjou’s picture

The patch works for me, the video is playing automatically now. Thank you!

EDIT: Actually, it depends on the video, if there is any special character like quote in the video, then it does not work.
It is due to the replacement.>
For example using this video: https://www.youtube.com/watch?v=UKcWushnRpQ

In the old tag, it will be:
title="Amir - États d'amour (Clip officiel)"
In the new tag, it will be:
title="Amir - États d'amour (Clip officiel)"

So the replacement doesn't work and the autoplay will not apply. I had a hard time to find the reason, I was becoming crazy. So happy I found the origin of the issue.

I'm working on a patch, coming soon...

phjou’s picture

Ok changes pushed to the merge request branch.

EDIT: I am not sure what's going on with the dev branch 2.x but impossible to pull it through composer.

phjou’s picture

Ok I pushed a new change reverting the encoding to use a single replace instead. It seems some characters like & are already & but the apostrophe is not. So the previous change broke videos with other special characters.

If we were directly using $dom->saveHTML then the issue would not even occur but since it creates problems with the css placeholders we cannot get rid of the str_replace approach and use saveHTML.

So I went down the road to use another replace to handle that case. The code for the apostrophe is not even ' but ' which I find strange as well.

The str_replace approach might have unexpected issues that we are not aware of, but so far the branch worked very well in that version and I could get all videos that I tested in autoplay.

igoragatti made their first commit to this issue’s fork.

igoragatti’s picture

I've reduced the str_replace to change only the src address, since that is the only thing we are changing on the markup I thought it would be cleaner that way

michaelmol’s picture

Status: Needs review » Reviewed & tested by the community

jacobbell84 made their first commit to this issue’s fork.

jacobbell84’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

coretex changed the visibility of the branch 3380731-youtube-mute to hidden.

coretex changed the visibility of the branch 3380731-youtube-mute to active.