Autoplay Embedded Youtube Videos
- Xibo for Android
- DSDevices DSCS9X/95 Set-up Guide
- Install a White Label or a different Player version on DSDevices
- CEC Screen Power on/off with DSDevices
- Hardware Recommendations
- Philips Signage SoC Monitors
- Sony Bravia SoC
- Managing Storage on the Android Device
- Player Settings
- Players without an Internet Connection
- Remote Administration with SS Helper
- Restart Rooted Device with a Shell Command
- Running Xibo for Android
- Resolving Common Issues
- Error shown when I try to licence my Player?
- Player not updating from the CMS?
- I can see my Licence entry but the Player appears unlicensed?
- Error message - Player is missing dependencies
- My scheduled Layouts are not working?
- Layout won't play? Splash screen plays?
- Watchdog error message
- Troubleshooting for Administrators
- Audit Trail
- Log Information
- Player Logs
- Getting the Player Status
- Request Player Status via CMS - Logged in Players only
- Request Player Status directly from a Device
- Can I use the Xibo name / logo?
- Can I run a Xibo Player on Raspberry Pi?
- How can I increase the upload file size limit?
- How do Players communicate with the CMS?
- How many displays can Xibo support?
- How do I reset the Xibo_admin account password?
- Power On/Off for Players
- Testing with Xibo
- Why do I need a Default Layout?
- Xibo for Android FAQ's
- Autoplaying Embedded Youtube Videos
- Closing to Home screen
- Displaying Images
- Embedded TV
- External SD card not listed when running Banana-Pi
- Helper Command to change Time zone
- HTML5 Video
- Memory Notifications
- Menu not accessible
- SSL Support
- Using Portrait Displays
- Video wont play properly
On this page
Autoplay Embedded Youtube Videos
Embedding a YouTube video should be done using an embedded widget. Please make sure you read and understand YouTube’s terms of service before publishing a Layout in Xibo which shows an embedded YouTube video.
First create an Embedded Widget.
In the HTML section, put the following:
<!-- BROWSER=edge -->
<div id="player"></div>
Then in the Head section put the following:
<script>
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;
var playerState = -1;
var readyCalled = false;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
suggestedQuality: 'hd1080',
height: '1080',
width: '1920',
videoId: 'onldzSzdqlM',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
readyCalled = true;
event.target.playVideo();
}
function onPlayerStateChange(event) {
if (readyCalled && playerState === 3 && event.data === -1) {
setTimeout(function() { player.playVideo(); }, 1000);
}
playerState = event.data;
}
</script>
In the script above, you’ll need to adjust the parameters to play the video you want and the size of the region it’s to be shown in.
So carefully adjust the following section:
height: '720',
width: '1280',
videoId: 'onldzSzdqlM',
The height and width are the size to show the video on your actual display. The videoId is from the Youtube URL for that video. So for example if your video’s URL was http://www.youtube.com/watch?v=onldzSzdqlM, the videoId parameter would be onldzSzdqlM
An example of a layout using the above method can be found here.
It is also highly recommended to make sure that “Hardware Accelerate web content” in display profile assigned to your device is set to “On” or “Off when transparent” (if you do not set transparency on the embedded widget), when set to Off player may have problems to display the videos/streams.
There are also additional parameters which can be added to the script, please see below:
player = new YT.Player('player', {
height: '1080',
width: '1920',
videoId: 'XCHMbYv70o8',
playerVars: {
'playlist': 'XCHMbYv70o8',
'loop': 1,
'controls' : 0,
'rel' : 0,
'fs' : 0,
'showinfo' : 0,
'cc_load_policy' : 0,
'iv_load_policy' : 3,
'modestbranding' : 1
},
playerVars are explained in the YouTube API Documentation, you can opt to use the ones you want. When we add ‘playlist’ with the same videoId as our video and loop parameter it will cause it to play that video in loop - of course you can add more videos, the above is just an example.
Other playerVars in the above example are mostly to remove unnecessary information, captions, controls etc from the embedded YouTube player.
Playlists
Autoplay and loop Playlists.
There are several ways to achieve this using Youtube iframe API, we will focus on loadPlaylist()
usage.
The following code will embed a Player, load the provided videoIds into a playlist, show all videos in order and then restart and loop the playlists from the beginning.
<script>
function onPlayerReady(event) {
event.target.loadPlaylist(['a329D581TAw','XCHMbYv70o8','wzQesXhFt_s']);
event.target.setLoop(true);
}
</script>
To use the playlist ID of an existing playlist on YouTube, we need to use object syntax to call loadPlaylist().
ie in the above example the loadPlaylist line would need to be replaced with
event.target.loadPlaylist({list:'PLYgi4FbOVUSzsP627x-PKTHjoS13_fSJE', listType: 'playlist'});