Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube Javascript API - disable related videos

Right, this seems to be poorly documented or I can't see it in the documentation. I basically want no related videos (?rel=0) using the JavaScript API.

$players[$vidIdPlaceholderRef] = new YT.Player('player_' + $vidIdPlaceholderRef, {     height: '550',     width: '840',     videoId: $vidId }); 

is what I have in place.

I have also tried:

$players[$vidIdPlaceholderRef] = new YT.Player('player_' + $vidIdPlaceholderRef, {     height: '550',     width: '840',     videoId: $vidId + '?rel=0',     rel : 0 }); 

with no luck. Does any one know of an option which can be added (tried rel : 0 with no luck )

like image 336
Phil Jackson Avatar asked Nov 16 '12 13:11

Phil Jackson


People also ask

What is YouTube iFrame API?

The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played.

What is iFrame API?

Developers can use the iFrame API to programmatically create and interact with an Embed or with multiple Embeds in the same web app. The iFrame API includes methods that you can use to start playback, change the content rendering in an Embed, or stop playback.


1 Answers

"rel" is a player parameter, as specified here:

https://developers.google.com/youtube/player_parameters#rel

To add player parameters to iframe players, you need to specify the playerVars property of the second constructor argument (at the time of writing this is documented here, and on the IFrame API documentation page)

e.g.

new YT.Player('playerid', {     height: '550',     width: '840',     videoID: 'video_id',     playerVars: {rel: 0, showinfo: 0, ecver: 2} }); 
like image 61
Tim Wintle Avatar answered Oct 04 '22 02:10

Tim Wintle