Search code examples
apiiframeyoutubevideo-streamingembed

Why can't I display an embedded video from a YouTube Live stream?


I found a script that lets me use the Youtube API to access a channel, recognise if there is any live stream and give me the id of this specific video that is being broadcasted.

However, when it is embedded on my page as:

<iframe width="500" height="600" src="//www.youtube.com/embed/{$this->live_video_id}{$autoplay}" frameborder="0" allowfullscreen>

I cannot play it. The video shows up, and when I press "play" it gives me a "Playback error".

I removed the $autoplay part because this was giving me problems and it worked! And then it didn't work. It's so frustrating. I copy-pasted the url only in my address bar

www.youtube.com/embed/[Whatever the id is here]

and it worked! And then it didn't work. I just cannot understand why it works sometimes and sometimes not.

Everytime I do something it works for 5 seconds and then it breaks and it doesn't want to show it. When I closed the live stream to try with another one. It showed the old (already archived) live stream. Nonsense!

I read somewhere that you need to embed the video from the live stream, but then the whole idea to use an API is futile. Also I tried enabling AdSense because this could also help, but it didn't.

What can I do to get an embedded YouTube live stream video on my website?


Solution

  • Update: Since I couldn't figure it out and YouTube tightened their API quota points a lot as of February 2019. I just switched to Twitch API and everything worked from the first try.