Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YouTube or Vimeo embed with autoplay? #14

Closed
proimage opened this issue May 12, 2019 · 8 comments
Closed

YouTube or Vimeo embed with autoplay? #14

proimage opened this issue May 12, 2019 · 8 comments

Comments

@proimage
Copy link

proimage commented May 12, 2019

I can't for the life of me figure out how to use this oEmbed plugin to parse a URL to a YouTube or Vimeo video and render an iframe with control over things like width/height and autoplay. Could you possibly provide a code example?

The problem I'm running into seems to be that the options object does nothing to affect the output. Here's my code:

{% set url = entry.oEmbedField %}
{% set options = {
	autoplay: 1,
	width: "800px",
	height: "450px"
 } %}
{{ craft.oembed.render(url, options) }}

The output ends up being this (linebreaks added for readability):

<iframe
    width="480"
    height="270"
    src="https://www.youtube.com/embed/[VIDEO_ID_HERE]?feature=oembed"
    frameborder="0"
    allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
    allowfullscreen=""></iframe>

Thanks for any help you can provide!

@reganlawton
Copy link
Member

I’m almost certain this is a feature you add in the URL, something like ?autoplay=1. I’ll have to check when I’m at my computer.

@gudehus
Copy link

gudehus commented May 16, 2019

I have the same problem with Vimeo videos. But they have a documentation that listed all the options.
https://developer.vimeo.com/api/oembed/videos

Maybe this is helping. And some code example would be helpful.

@reganlawton
Copy link
Member

It seems the library embed is stripping the URL I'll have to have a play with this.

@reganlawton
Copy link
Member

I think I have a way around this by using PHP to edit the DOM on the iframe. I'll need to look into this abit more.

@reganlawton
Copy link
Member

Seems to be linked to this issue, I still think DOM manipulation might be the way I've still got some playing around to do

reganlawton added a commit that referenced this issue Aug 15, 2019
@reganlawton
Copy link
Member

@proimage and @gudehus are you able to checkout using composer, dev-feature/autoplay. It should let you support autoplay on videos. Its hijacking the URLs and reformatting it. I also added more support for additional vimeo options.

reganlawton added a commit that referenced this issue Sep 16, 2019
…feature via DOM manipulation. ([#14](#14))

- Array to string conversion bug due to lack of a recursive function. ([#17](#17))
@reganlawton
Copy link
Member

Deployed fix in v1.1.8

@linehammer
Copy link

Since April 2018, Google made some changes to the Autoplay Policy. You not only need to add the autoplay=1 as a query param, but also add allow='autoplay' as an iframe's attribute

So while embed youtube video, you will have to do something like this:

<iframe src="https://www.youtube.com/embed/VIDEO_ID?autoplay=1" allow='autoplay'></iframe>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants