ispiro
ispiro

Reputation: 27633

Muting an embedded YouTube video without using SWFObject

It seems from here: that using a SWFObject is optional. Since I have a simple requirement (- only to mute a video), I tried the following code, but onYouTubePlayerReady doesn't get called at all (-I put an alert there and it never fired).

What's missing from this code?

<iframe id="id1" width="640" height="360" src="http://www.youtube.com/embed/shbgRyColvE?version=3;enablejsapi=1" allowscriptaccess="true" ></iframe>

Upvotes: 1

Views: 4742

Answers (1)

Jeff Posnick
Jeff Posnick

Reputation: 56034

First off, you're using the iframe Player, which is good—it's newer than the Flash-only player (which is where SWFObject comes into play) and it's what we recommend for new development.

If you want to make API calls against the iframe Player, you need to initialize things a bit differently, though. You can follow the example at

https://developers.google.com/youtube/iframe_api_reference#Getting_Started

and modify the onPlayerReady event handler in that example to explicitly mute the player, i.e.

function onPlayerReady(event) {
  event.target.mute();
  // Anything else you want to do, like start playback...
}

Upvotes: 3

Related Questions