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

2

6

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"]
Coadjutress answered 28/8, 2018 at 16:2 Comment(0)
C
15

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)
Coadjutress answered 28/8, 2018 at 19:10 Comment(2)
The origin property did it for me. Thanks for sharingSinciput
What is this sorcery? It does seem to work, but did anyone figure out why?Tierell
H
2

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.

Humiliation answered 28/8, 2018 at 16:32 Comment(2)
I meant some videos (limited amount) still work and most don't. The issue I have is that I had these videos in a playlist from a couple of weeks ago and had tested them, and they all seemed to play properly. I'm wondering if there's any workaround to it?Coadjutress
Ok, but how to filter out these videos from search result?Prosser

© 2022 - 2024 — McMap. All rights reserved.