5
votes

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"]
2

2 Answers

13
votes

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)
1
votes

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.