Automatically Displaying the latest 5 videos for youtube in a html - html

I am trying to display the lastest five videos from my youtube channel on one HTML page. I have managed to successfully embed one youtube video with this code but I am unable to upload any other one. I have tried to embed the second latest video as well but no matter what I try, I get a playback error with invalid ID as seen above. Does anyone have a clue how I could embed the latest 5 videos from my YouTube Chanel in JSON/JavaScript?
Below is my code
var channelID = "MY-ID";
var reqURL = "https://www.youtube.com/feeds/videos.xml?channel_id=";
$.getJSON("https://api.rss2json.com/v1/api.json?rss_url=" + encodeURIComponent(reqURL)+channelID, function(data) {
var link = data.items[0].link;
var id = link.substr(link.indexOf("=")+1);
$("#youtube_video").attr("src","https://youtube.com/embed/"+ id + "?controls=0&showinfo=0&rel=0");
});
<iframe id="youtube_video" width="600" height="340" frameborder="0" allowfullscreen></iframe>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

I Found It you have to change the number in the []'s.
var channelID = "MY-ID";
var reqURL = "https://www.youtube.com/feeds/videos.xml?channel_id=";
$.getJSON("https://api.rss2json.com/v1/api.json?rss_url=" + encodeURIComponent(reqURL)+channelID, function(data) {
var link = data.items[0].link;
var id = link.substr(link.indexOf("=")+1);
$("#youtube_video").attr("src","https://youtube.com/embed/"+ id + "?controls=0&showinfo=0&rel=0");
var link = data.items[1].link;
var id = link.substr(link.indexOf("=")+1);
$("#youtube_video2").attr("src","https://youtube.com/embed/"+ id + "?controls=0&showinfo=0&rel=0");
var link = data.items[2].link;
var id = link.substr(link.indexOf("=")+1);
$("#youtube_video3").attr("src","https://youtube.com/embed/"+ id + "?controls=0&showinfo=0&rel=0");
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<iframe id="youtube_video" width="600" height="340" frameborder="0" allowfullscreen></iframe>
<iframe id="youtube_video2" width="600" height="340" frameborder="0" allowfullscreen></iframe>
<iframe id="youtube_video3" width="600" height="340" frameborder="0" allowfullscreen></iframe>

Related

convert youtube video id from url

<div class="container">
https://youtu.be/_32C_wVWEF0
</div>
div class(video-container) is not created
I want to create a div class (video-container) where I want.
please help fix the code. 😭
Find the link in the text and convert it to the embed code
Please let me know if there is any other way.
<script>
function youtubeParser(url, ...young) {
console.log(url);
const container = `
<div class="video-container" style="width: 100%; height:100%">
<iframe width="560"
height="315"src="https://www.youtube.com/embed/#ID#?rel=0&controls=0"
title="YouTube video player"
frameborder="0" allow="accelerometer; autoplay; clipboard-write;
encrypted-media; gyroscope; picture-in-picture"
allowfullscreen; ></iframe>
</div>`;
return young && young[6].length == 11
? container.replace("#ID#", young[6])
: url;
}
const content = document.querySelector("body");
const youtubeUrlExp = /(http:|https:)?(\/\/)?(www\.)?
(youtube.com|youtu.be)\/(watch|embed)?(\?v=|\/)?(\S+)?/g;
const wrappedContent = content.innerHTML.replace(youtubeUrlExp,
youtubeParser);
content.innerHTML = wrappedContent;
</script>

iFrames use according to user OS

I want to show one out of two iframe, according to user OS.
if user use iOS it shows one and if androind it show other.
<iframe id="e8e2c112-f7ce-4d21-96e7-59729619a527" src="https://www.vectary.com/viewer/v1/?model=e8e2c112-f7ce-4d21-96e7-59729619a527" frameborder="0" width="50%" height="480"></iframe>
you could detect userAgent in Javascript, like this.
<html>
<body>
<div id="vectary"></div>
<script>
function getOs() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/android/i.test(userAgent)) {
//Vectary iframe 1 - for Android
return '<iframe id="e8e2c112-f7ce-4d21-96e7-59729619a527" src="https://www.vectary.com/viewer/v1/?model=e8e2c112-f7ce-4d21-96e7-59729619a527" frameborder="0" width="50%" height="480"></iframe>';
}
// iOS detection from: http://stackoverflow.com/a/9039885/177710
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
//Vectary iframe 2 - for iOS
return '<iframe id="e8e2c112-f7ce-4d21-96e7-59729619a527" src="https://www.vectary.com/viewer/v1/?model=e8e2c112-f7ce-4d21-96e7-59729619a527" frameborder="0" width="50%" height="480"></iframe>';
}
//Vectary iframe 3 - for all other cases
return '<iframe id="e8e2c112-f7ce-4d21-96e7-59729619a527" src="https://www.vectary.com/viewer/v1/?model=e8e2c112-f7ce-4d21-96e7-59729619a527" frameborder="0" width="50%" height="480"></iframe>';
}
document.getElementById("vectary").innerHTML = getOs();
</script>
</body>
</html>

Show YouTube video in Twig from the URL

I'm trying to show Youtube videos in Symfony (in the Twig template). I can't use the iframe method because I need to use the general URL (https://www.youtube.com/watch?v=jUjeps1hxIw&t=671s instead of https://www.youtube.com/embed/jUjeps1hxIw).
I have found examples with the HTML tag but they doesn't work.
Finally I have found a solution. I had to change the url, what is that I didn't want.
<div id="youtube-ficha">
{% for artistYoutube in group.youtube %}
<iframe class="myIframe" width="560" height="315" frameborder="0" allowfullscreen></iframe>
<script type="text/javascript">
var url = "{{ artistYoutube}}";
var id = url.split("?v=")[1]; //sGbxmsDFVnE
var embedlink = "http://www.youtube.com/embed/" + id;
var ytube1 = document.getElementsByClassName("myIframe");
ytube1[{{loop.index0}}].src = embedlink;
</script>
{% endfor %}
</div>
If you don't want to use tag you can use
<object width="420" height="315"
data="https://www.youtube.com/embed/jUjeps1hxIw">
</object>
<embed width="420" height="315"
src="https://www.youtube.com/embed/jUjeps1hxIw">
but you have to give the embed link of your you tube video which you can find by following below steps
play your video on you tube
right click on your video
select copy embed code
past it in notepad and copy that link and use it in above tag

Looping through pages using Iframe?

function changeIframeSrc(index){
var iframeid = document.getElementByID('changingIframe');
iframeid.setAttribute('src', sourceList[index]);
}
var i = 0;
var sourceList = ['111.php', '222.php', '333.php'];
setInterval(function(){ changeIframeSrc(i++);
// loop properly
if(i == sourceList.length){ i = 0; }
}, 10000);
<iframe id="changingIframe" src="" scrolling="no" width="100%" height="87%"></iframe>
<html>
<body>
<div class="wrapper">
<iframe id="111" src="111.php" scrolling="no" width="100%"></iframe>
<iframe id="222" src="222.php" scrolling="no" width="100%"></iframe>
<iframe id="333" src="333.php" scrolling="no" width="100%"></iframe>
<iframe id="bottom_banner" src="bottom_banner.php" scrolling="no" width="100%"></iframe>
</div>
</body>
I want my page to change between pages 111,222,333 on a loop every 10 seconds.
I could use etc. on each page but my banner keeps duplicating on each loop. (therefore stacking up)
I want to keep my banner at the bottom at all times. I want my pages to take up 80% of the height and the banner to take up the 20% left over.
You could use Javascript/jQuery to change the source of the iframe that keeps changing source
So
function changeIframeSrc(index){
var iframeid = document.getElementById('changingIframe');
iframeid.setAttribute('src', sourceList[index]);
}
and then
var i = 0;
var sourceList = ['111.php', '222.php', '333.php', etc];
setInterval(function(){ changeIframeSrc(i++);
// loop properly
if(i == sourceList.length){ i = 0; }
}, 10000);

Muting an embedded vimeo video

On a website I am building I have a vimeo video embedded. The client needs to keep the sound on the video obviously for people that find it on vimeo. However for her website the sound is just plain annoying. So I need to find a way to mute the audio within the code for the embed. I have googled it but can't seem to find anything legible. As you can see from my code below, I have used the autoplay command within the link I was hoping I could do a similar thing to mute the sound.
<iframe src="http://player.vimeo.com/video/4415083? title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
Thanks
In case it helps anyone, Vimeo have added a 'background' parameter for embedding videos, that autoplays videos silently. In some cases that will be useful where people want to mute videos - this is their example:
<iframe src="https://player.vimeo.com/video/76979871?background=1"
width="500" height="281" frameborder="0" webkitallowfullscreen
mozallowfullscreen allowfullscreen></iframe>
For non-paying members
You just need to add the muted parameter. E.g.:
<iframe src="https://vimeo.com/48400332?autoplay=1&loop=1&muted=1" ></iframe>
For paid members
According to Vimeo, the background parameter is only supported for videos hosted by paid members.
Source: https://help.vimeo.com/hc/en-us/articles/115004485728-Autoplaying-and-looping-embedded-videos
you will be using setVolume api in your vimeo.. player.api('setVolume', 0);
it will be like this...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="http://player.vimeo.com/video/4415083?title=0&byline=0&portrait=0&color=d01e2f&autoplay=1&player_id=vimeo_player" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<script>
var iframe = $('#vimeo_player')[0],
player = $f(iframe),
status = $('.status');
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
</script>
I tried the examples in the answers with no luck. After looking into the documentation I noticed there is missing the parameter &player_id=IFRAME_ID. Maybe something changed in the Vimeo API, anyway the following example works for me:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="//player.vimeo.com/video/4415083?api=1&player_id=vimeo_player&autoplay=1&loop=1&color=ffffff" width="1920" height="1080" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<script>
$(function() {
var vimeo_iframe = $('#vimeo_player')[0];
var player = $f(vimeo_iframe);
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
});
</script>
Seems like Vimeo is providing an updated library, and the API syntax is a bit different from the old one (Froogaloop). Here's how to mute an embedded video with JS:
<!--Add the id attr to the iframe tag to use as a selector-->
<iframe id="embeddedVideo" src="http://player.vimeo.com/video/4415083? title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<!--Include the Vimeo API Library-->
<script src="https://player.vimeo.com/api/player.js"></script>
<!--Select and manipulate your video-->
<script type="text/javascript">
//Select the #embeddedVideo element
var video = document.getElementById('embeddedVideo');
//Create a new Vimeo.Player object
var player = new Vimeo.Player(video);
//When the player is ready, set the volume to 0
player.ready().then(function() {
player.setVolume(0);
});
</script>
Hope this helps out anyone who's using the new library. Documentation is at vimeo/player.js
Since most of the answers here are referring to Vimeo's old api. Here is the simplest way with the new api. You can include vimeo player.js from their CDN or you can download it or you can include it from npm.
<script src="https://player.vimeo.com/api/player.js"></script>
or
npm install #vimeo/player
then you can do the following.
<script>
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);
player.setVolume(0);
</script>
that's it. And if you are using angular 2+,
import * as Vimeo from '#vimeo/player';
const iframe = e.target;
const player = new Vimeo(iframe);
player.setVolume(0);
here e.target is $event which would be passed from the template. Probably it could be iframe (load) event. Or may be you can use jquery to select iframe.
#Gadss answer works great but I found that you need update the iframe src to include the activation of the Vimeo api. Just include api=1 after the vimeo id.
I've also found that this sometimes doens't work on Safari for some reason.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="vimeo_player" src="http://player.vimeo.com/video/4415083?api=1&title=0&byline=0&portrait=0&color=d01e2f&autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<script>
var iframe = $('#vimeo_player')[0],
player = $f(iframe),
status = $('.status');
player.addEvent('ready', function() {
player.api('setVolume', 0);
});
</script>
**Here is my solution:
http://jsfiddle.net/jakeoblivion/phytdt9L/5/
(You will need your own play/pause mute/unmute icons)
//load video muted
var video = $("#myvideo");
video.vimeo("play");
video.vimeo("setVolume", 0);
//toggle play/pause
$('#play-pause').click(function() {
$(this).toggleClass('play');
if ($(this).hasClass('play')) {
//pause video
video.vimeo("pause");
$(this).css('background', 'pink');
} else {
//unpause video
video.vimeo("play");
$(this).css('background', 'blue');
}
});
//toggle mute/unmute
$('#mute-unmute').click(function() {
$(this).toggleClass('mute');
if ($(this).hasClass('mute')) {
//unmute video
video.vimeo("setVolume", 1);
$(this).css('background', 'green');
} else {
//mute video
video.vimeo("setVolume", 0);
$(this).css('background', 'red');
}
});
Spent ages trying and nothing seemed to work to.
I just wanted to have a Vimeo autoplay muted (volume 0) with simple Play/Pause Mute/Unmute controls, instead of their default ones. (feel free to use icons instead of the temporary colours I put).
(if you want to add the default controls back but keep muted, remove "?background=1". By default background=1 will set video.vimeo("setVolume", 0) and hide controls, so I also added the mute on load without the background=1 set).
Also note:
"You’ll need to be running on a web server instead of opening the file directly in your browser. JS security restrictions will prevent the API from working when run locally."
I've found a way to do it. You start the video muted so it autoplays, then on the first timeupdate you set the volume to 1.
var options = {
id: 'video_id_here',
width: 640,
loop: false,
muted: true,
autoplay: true
};
var player = new Vimeo.Player('vimeo', options);
player.setVolume(0);
player.on('timeupdate', set_autoplay_volume );
function set_autoplay_volume(){
player.setVolume(1);
player.off('timeupdate', set_autoplay_volume );
}
You try insert ?muted=1 after link in attribute src
For example
<iframe id="vimeo_player" src="https://player.vimeo.com/video/257992348?muted=1">
This is the only way it worked for me: http://jsfiddle.net/87dsjL8q/108/
var iframe = document.getElementsByTagName('iframe')[0];
var player = $f( iframe );
player.addEvent('ready', function() {
player.api('setVolume', 20);
});
<iframe src="http://player.vimeo.com/video/4415083?muted=1; title=0;byline=0;portrait=0;color=d01e2f;autoplay=1" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
you can just give "muted=1" so the video will be muted...
chrome allow the videos autoplay that are muted