Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube IFrame Player shows 'This Video is Unavailable' when play button is pressed

I embedded YouTube iframe player into my ios application. Everything was working and loading fine then couple days ago when testing the app, I noticed that it no longer plays certain videos and I'm not sure what's causing it. I tested this with multiple videos that still work on the YouTube App but when will no longer play within my application. The thumbnail for the video is shown and as soon as I press play it shows, 'This video is unavailable' in the player window. Some videos still play normally which lets me know that the videoID and loading of the video is working.

Here is the code I'm using to load the video:

    let playerVars: [AnyHashable: Any] = ["playsinline" : 1]
    self.playerView.load(withVideoId: videoID, playerVars: playerVars)

Below are two images of what the YouTube Iframe player shows before and after play is pressed. Video Preview

Video Unavailable

I saw that some people were having similar issues and I've tried following their examples on how to fix the issue but nothing has worked for me so far. Can anyone help me fix this problem?

FIX

I was able to finally find a workaround for this issue by changing the first line of code above to this.

let playerVars: [AnyHashable: Any] = ["playsinline" : 1,
                                      "origin": "https://www.youtube.com"]
like image 291
Shukti Avatar asked Aug 28 '18 16:08

Shukti


People also ask

Why does my embedded YouTube video say video unavailable?

Lastly, always keep in mind that videos that have this message: “Video unavailable, watch on youtube” means that the embedding of the video or in the Video Privacy settings, is restricted. It might also be related to a copyright claim on the video.

What is YouTube iFrame api?

The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played.

What is iFrame api?

Developers can use the iFrame API to programmatically create and interact with an Embed or with multiple Embeds in the same web app. The iFrame API includes methods that you can use to start playback, change the content rendering in an Embed, or stop playback.


2 Answers

After doing some more research I was able to find a workaround.

I just changed the above code from this:

let playerVars: [AnyHashable: Any] = ["playsinline" : 1]
self.playerView.load(withVideoId: videoID, playerVars: playerVars)

to this:

let playerVars: [AnyHashable: Any] = ["playsinline" : 1,
                                      "origin": "https://www.youtube.com"]
self.playerView.load(withVideoId: videoID, playerVars: playerVars)
like image 139
Shukti Avatar answered Sep 20 '22 23:09

Shukti


This appears to be the result of YouTube limiting where some videos can be played. You said other videos do work still, but not this one, which is a music video, which is often limited by YouTube.

like image 39
Ron Davis Avatar answered Sep 20 '22 23:09

Ron Davis