Youtube Javascript API-wyłącz powiązane filmy
Racja, to wydaje się być słabo udokumentowane lub nie widzę tego w dokumentacji. W zasadzie nie chcę żadnych powiązanych filmów (?rel=0
) za pomocą JavaScript API.
$players[$vidIdPlaceholderRef] = new YT.Player('player_' + $vidIdPlaceholderRef, {
height: '550',
width: '840',
videoId: $vidId
});
To jest to, co mam na miejscu.
Ja też próbowałem:
$players[$vidIdPlaceholderRef] = new YT.Player('player_' + $vidIdPlaceholderRef, {
height: '550',
width: '840',
videoId: $vidId + '?rel=0',
rel : 0
});
Bez powodzenia. Czy ktoś zna opcję, która może być dodana (wypróbowana rel : 0
bez powodzenia ) 6 answers
" rel " jest parametrem gracza, jak określono tutaj:
Https://developers.google.com/youtube/player_parameters#rel
Aby dodać parametry odtwarzacza do odtwarzaczy iframe, musisz określić właściwość playerVars drugiego argumentu konstruktora (w momencie pisania tego jest to udokumentowane tutaj oraz na stronie dokumentacji API IFrame )
Np.
new YT.Player('playerid', {
height: '550',
width: '840',
videoID: 'video_id',
playerVars: {rel: 0},
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-06 10:29:14
Przyjęte rozwiązanie nie działało dla mnie. Co działa to:
1) umieszczenie ramki iframe w html, która zawiera parametr rel
<iframe id="youtube-video" width="560" height="315"
src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&rel=0&modestbranding=1"
frameborder="0" enablejsapi="1" allowfullscreen></iframe>
2) używanie javascript API do dołączania do istniejącego odtwarzacza
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('youtube-video', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
console.log("ready");
}
function onPlayerStateChange(event) {
console.log("state changed");
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-05 21:39:37
Jeśli używasz SWFObject, po prostu musisz zrobić coś takiego:
function loadVideo() {
var params = { allowScriptAccess: "always" }
, atts = { id: "myvideo" }
;
//NOTE THE END OF THE BELOW LINE vvvvvv
swfobject.embedSWF("https://www.youtube.com/v/[video id here]?enablejsapi=1&playerapiid=myvideo&version=3&rel=0"
, "videoplaceholderid"
, "768", "432", "8", null, null, params, atts);
}
Wystarczy dodać rel=0
na końcu adresu url.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-09 02:18:17
Nie ma potrzeby kodowania przez API,teraz łatwo można to zrobić przez
You tube embed przycisk - > Pokaż więcej - > zaznacz opcję "Pokaż sugerowane Filmy, gdy film się skończy"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-10 14:34:33
Oto szybkie rozwiązanie:
setInterval(function(){
if($('iframe').length > 0){
$('iframe').each(function(){
if($(this).hasClass('gotYou')){
//do nothing
}else{
var getMySrc = $(this).attr('src');
var newSrc = getMySrc.split('?');
console.log(newSrc);
var freshURL = newSrc[0]+'?rel=0&'+newSrc[1];
console.log(freshURL);
$(this).addClass('gotYou');
$(this).attr('src', freshURL );
}
});
}
}, 1);
Co to robi, szuka ramki iframe w dokumencie. Jeśli znajdzie ramkę iframe, przechwyci src ramki iframe, znajdzie znak ?
, a następnie zastąpi ?
przez ?rel=0&
. Tutaj celem jest wyjście rel=0
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-23 03:18:05
new YT.Player('playerid', {
height: '550',
width: '840',
videoID: 'video_id',
playerVars: {rel: 0},
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-23 05:20:50