How to embed youtube livestream chat - html

I'm trying to embed a youtube livestream chat onto a webpage on my website,
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/live_chat?v=hHW1oY26kxQ&embed_domain=localhost" width="480"></iframe>
I'm trying this, but the chat doesn't show up at all, if tried doing embeded domain using a real domain I own, but that doesn't work either.

It seems to me that YouTube disabled the feature to embed a live chat on external websites, but then forgot to update the documentation. Or alternatively, there could be an unfixed bug that broke this feature.
2021 update: chat embedding works again. Uses the same syntax as before. As per a helpful comment below.
Details
The YouTube knowledge base still says that embedding a live chat iframe into an external website is still possible, using a URL like the one you posted (see here, in section "Embed Live chat").
However, when trying that and looking into the browser's console, you will see a message like this:
Refused to display 'https://www.youtube.com/live_chat?v=12345&embed_domain=example.com' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
You can also see that x-frame-options: SAMEORIGIN header in the "Network" tab of the browser's developer tools when looking at the response to the https://www.youtube.com/live_chat?… request.
This means that YouTube does not want a browser to embed this into an iframe except when embedded on youtube.com itself. (On YouTube itself, this embed code still works: when you inspect the source code of any currently streaming live video on YouTube, you will find that the live chat window there is made with that same /live_chat?… request, in an iframe.)
Additional indications that this feature has been removed:
The YouTube documentation mentions:
The Live chat module only exists on the YouTube watch pages — it does not follow embedded players. (source)
I believe that's the new part of the documentation, and the section "Embed live chat" further down is outdated.
This tutorial from 2016 uses the documented URL format to embed an example live chat near the bottom, and it now shows the same "Refused to display […] in a frame because it set 'X-Frame-Options' to 'sameorigin'." Assuming that this worked in 2016, something must have changed on YouTube's side.
This Reddit thread tells how somebody's embedded live chat suddenly stopped working in early September 2018 – so shortly before this question got asked.
Alternatives
You could use the YouTube Livestream API, in particular the LiveChatMessages endpoint, to get and create chat messages. There are probably open source libraries around to help with this. So far, I found this one (able to display but not create chat messages).
You could embed your own chat, either installed on your own server or a cloud-hosted livestream chat solution. This solution can also provide features that YouTube live chat does not provide, such as allowing anonymous visitors to post.
You could reverse proxy the https://www.youtube.com/live_chat?… URL, forwarding YouTube's response but with the X-Frame-Options header removed.
If you only need a solution for one or a few computers, you could use a browser extension to remove the X-Frame-Options header from YouTube's response. See this question.

This appears to have to do with the introduction of this change to iframes, at least when I had this issue.
To fix this, I would suggest the use of a script like the following:
<script>
let frame = document.createElement("iframe");
frame.referrerPolicy = "origin";
frame.src = "https://www.youtube.com/live_chat?v=VIDEO_ID&embed_domain=" + window.location.hostname;
frame.frameBorder = "0";
frame.id = "chat-embed";
let wrapper = document.getElementById("chat-embed-wrapper");
wrapper.appendChild(frame);
</script>
Where chat-embed-wrapper is the parent of the iframe with the id chat-embed and VIDEO_ID (in the frame.src assignment) is the id of your target video. You'll have to modify this a little for your setup, but this is the general case solution.

Simple solution for Angular :
HTML part :
<iframe frameborder="0" height="470" [src]="url" width="780"></iframe>
TS part :
constructor(private sanitizer: DomSanitizer) {}
ngOnInit() {
this.url = this.sanitizer.bypassSecurityTrustResourceUrl('https://www.youtube.com/live_chat?v=[YOUR_LIVESTREAM_ID]&embed_domain=' + window.location.hostname);
}

I'm not sure if you got this working in the end? We have managed to get it working on our site using this iframe, hope it helps you:
<iframe src="https://www.youtube.com/live_chat?v=YourVidCodeHere&embed_domain=www.YourDomainHere.com"width="100%" height="600"></iframe> 
I hope that helps:) PS it doesn't work on mobile (YouTube said they have removed this feature from mobile), but it does work on desktop and tab.
Best wishes.

I can confirm this indeed works. However, I received the same X Frame error when embed_domain had the value "example.com" even though the url of the page started with "https://www.example.com". i.e. ensure the value matches window.location.hostname. Addison Crump's workaround could work for this if you do not have canonical host redirection working.

Related

Using google drive to stream video into html5 player

I tried to use google drive as a place to host videos, but whenever I try to use the video as a source, google never returns anything. (Not even a http response)
Example video player
<video>
<source
src="https://www.googleapis.com/drive/v3/files/<file_id>/?alt=media&key=<api_key>"
type="video/mp4"
/>
</video>
If I enter the url in the browser it successfully prompts me for permission to download.
Does anybody have any idea what to do?
// This works...
<video src="https://www.googleapis.com/drive/v3/files/fileID?alt=media&key=apiKey">
// But, even better if you have access to a worker or can otherwise output the file through a script (and modify resonse headers)
async function getFile(request) {
let response = await fetch('https://www.googleapis.com/drive/v3/files/fileID?alt=media&key=apiKey', request)
response = new Response(response.body, response)
response.headers.set('Accept-Ranges', 'bytes') // Allow seeking, not necessarily enabled by default
response.headers.set('Content-Disposition', 'inline') // Disable Google's attachment (download) behaviour, display directly in browser or stick into video src instead
return response
}
addEventListener('fetch', event => {
event.respondWith(getFile(event.request))
})
Short answer: Nope
Longer answer: Oh boy. I spent quite a long time trying to figure this one out myself! I'm working on a project called DriveStream, that aims to use purely JavaScript and Apps Script to make an organised video library of a Drive account.
The project itself works fine, but implementing video streaming did not go anywhere near as planned. I tried a few different methods. One similar to yours and the other involving getting the downloadUrl property of a file and parsing the html of the download prompt page to give me a direct link to the file. I can initiate a download of that file, and that can be seen in the network requests, but there is no way to get it to stream into a video container.
The reason that doesn't work is due to the limitations of AJAX. It can return the data from a video, but there seems to be no way to funnel that data into a video container.
In the end, I've had to compensate by having the 'Play' button of each video only link to the preview video.
https://drive.google.com/file/d/fileId/preview
It's not a bad workaround, as it can play up to 1080p encodes of anything you upload.
This should work:
<video>
<source src="https://drive.google.com/uc?export=download&id=file_ID" type='video/mp4'>
</video>
Replace "file_ID" in the link with your video ID. (to find it - right click on the Google Drive video, get shareable link. The file should be shared in order to access the file.)
It plays the source video. If you would like to change quality or to use unsupported codecs it's not easy to get google drive stream/converted files as said in previous answer. (Ajax will not let you get the link because of CORS and PHP is server side and the link contains an IP address so will not be accessible directly from client side.)
It's a long answer I will try to shorten it up..
Upload your file to the drive and using the share option make it public.
Then click on the preview option, and it will open a new tab.
Look for the vertical 3 dots (top right corner) leading to a sub-menu and select open in a new window.
As soon as you get to the new window click on the vertical 3 dots (top right corner) and this time you will see an 'Embed item' option click it.
You will get the iframe code now include it your webpage or website.
Just give it a try once!!!
I hope this helps thank you!!
I might be a bit late to answer, but if anyone's interested, I have written an answer on streaming videos from Google Drive before here. There are a few ways to go about this, but in summary, you will have to do some server-side programming (can be ASP.NET, PHP etc.) if you don't want to use Google Drive's embedded player. Alternatively, if you have large videos that you want to stream that exceed the limit of 100MB, have you looked into HLS (HTTP Live Streaming)? You can create .m3u8 playlists with segments of your video (preferably less than 100MB) and that way, you can stream your videos. I hope my answer helps!

How to post a video in an ifram to facebook? [duplicate]

When something is shared from youtube to facebook, facebook is now showing the youtube html5 player.
If you look up one of their urls (https://www.youtube.com/watch?v=uuS5ZyQhvsk) in the open graph debugger you can see that they are now providing open graph meta data for their html player as well as the flash one.
I also have a player that sits in an iframe, and am now including the same tags that youtube is, minus the flash ones as we don't have a flash player, but it isn't working and facebook is giving me this error which doesn't make sense:
Share has playable media but will not play inline because it would cause a mixed content warning if embedded. Add a secure_src or make the video src secure to fix this.
This is the information facebook is reading:
This is the url as an example that is generating that error: https://www.la1tv.co.uk/player/124/260
All I can think is that Facebook has made some kind of deal with youtube and this isn't available for everyone yet, but that isn't clear from that error.
All of the content on our site is served over https.
Anyone know what's going on or got this working?
I can't find any documentation anywhere on facebook how to do this.
I posted a similar question a while back when I was trying to get this working but at this time youtube was still only providing the flash player to facebook.
It looks like someone else was having a similar issue here.
According to WizKid this is currently in a trial period for YouTube and hopefully will be rolled out to everyone at a future date.

Cannot play specific youtube videos through Youtube API

The main action of my app (Windows Phone 8.1) requires requesting videos from Youtube playlist and playing them. I've been on it for the past couple of months and until then it was working well. Note : I don't have the "official player" from Youtube since it seems it doesn't exist, but I use the MediaElement
Recently (a week ago) I realized that I couldn't play some of the videos anymore . And after not being able to find anything I come to you guys.
I have no error through the requests to Youtube Api but some videos cannot be played, they just don't start as I get no error since it's not the official player. Thing is I didn't changed anything in the past two months on those requests so I can't understand what changed as I didn't see any update on the Youtube Documentation (or wasn't notified).
I use the Youtube object in the MyToolkit package to get the video url of it
YouTube.GetVideoUriAsync(videoUrl, YouTubeQuality.Quality480P);
Which give me this url which could be expired by the time you read this that just redirects me to a white page instead of the video
I checked if there were some Region/Country lock : null
VideoEmbeddable : true
Licence : Youtube
Privacy : Public
EDIT: See answer below
Answer: If people ever come across this question, the issue came from the library used to retrieve the Youtube videos from MyToolKit
Github Issue link
It should be fixed in the version stated in the link

Embedding video player html5 iframe in facebook share like YouTube

When something is shared from youtube to facebook, facebook is now showing the youtube html5 player.
If you look up one of their urls (https://www.youtube.com/watch?v=uuS5ZyQhvsk) in the open graph debugger you can see that they are now providing open graph meta data for their html player as well as the flash one.
I also have a player that sits in an iframe, and am now including the same tags that youtube is, minus the flash ones as we don't have a flash player, but it isn't working and facebook is giving me this error which doesn't make sense:
Share has playable media but will not play inline because it would cause a mixed content warning if embedded. Add a secure_src or make the video src secure to fix this.
This is the information facebook is reading:
This is the url as an example that is generating that error: https://www.la1tv.co.uk/player/124/260
All I can think is that Facebook has made some kind of deal with youtube and this isn't available for everyone yet, but that isn't clear from that error.
All of the content on our site is served over https.
Anyone know what's going on or got this working?
I can't find any documentation anywhere on facebook how to do this.
I posted a similar question a while back when I was trying to get this working but at this time youtube was still only providing the flash player to facebook.
It looks like someone else was having a similar issue here.
According to WizKid this is currently in a trial period for YouTube and hopefully will be rolled out to everyone at a future date.

Iframes not working

I'm trying to get Iframes to work. I'm running safari, so it is compatible, but when I test it, it comes up blank.
Code:
<iframe src="http://www.google.com" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
I took the code directly from the w3schools website after using the "try it out" editor so I know it's supposed to work. When I changed the page from a page in their subdirectory to an external page, it shows up blank.
The syntax is correct. It's not your fault - Google is blocking iframing using the X-Frame-Options header that newer browsers listen to.
Possible workarounds are explained in this Google forum post.
Follow the instruction in the following Google Developer Site under "IFrame embeds using the IFrame Player API" bullet:
https://developers.google.com/youtube/player_parameters
This uses API's JavaScript code to view youtube videos.
Here's the link with a more general instruction
https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player