Playback restricted on iOS for VEVO videos from YouTube API
Asked Answered
K

3

10

I have embedded videos (pulled from YouTube API v3) into my iPhone app using a UIWebView as suggested. The problem is that some videos, such as those from VEVO, produce the following error when attempting to play them on the device.

This video contains content from VEVO. It is restricted from playback on certain sites.

This should not occur, since apps like Flipboard and Rockpack also seem to be using a UIWebView, and are able to play videos from VEVO and other sources.

What could I be doing wrong?

PS: I am aware that there exist other posts that touch upon this issue in some way, but they fail to address this specific problem.

Koblenz answered 6/11, 2013 at 18:35 Comment(5)
Were you able to get somewhere with this ?Homogenesis
Unfortunately, no. This has not been a major part of my project, so I shelved it for now. If anyone has a solution, I am all ears.Koblenz
I have noticed performing a search with the YouTube Data API that different results are returned for iOS. The app is searching for film clips, and the official film clips are omitted from the API response.Cavour
Have you resolved this thing ?Kyle
@Koblenz you should accept an answer if one has helped you.Gatehouse
G
15

Using YouTube's YTPlayerView for iOS and setting the origin property to a valid URL allows many VEVO videos to be played properly.

In your View Controller:

@property (weak, nonatomic) IBOutlet YTPlayerView *playerView;

// ..

NSDictionary *playerVars = @{
                             @"playsinline" : @1,
                             @"showinfo" : @0,
                             @"rel" : @0,
                             @"controls" : @1,
                             @"origin" : @"https://www.example.com", // this is critical
                             @"modestbranding" : @1
                             };

[self.playerView loadWithVideoId:@"Ri7-vnrJD3k" playerVars:playerVars];

With origin: origin

Without origin: no origin

Gatehouse answered 25/6, 2015 at 20:28 Comment(4)
Thanks, I could not access Youtube video, your solution saved my day ;)Reese
So, I just need to set the origin as example.com? Is it literally example.com? or do I have to adapt it to me own case?Quillet
@UniSoundWaterloo I mean theoretically example.com would work, but it would be abuse of the origin parameter as outlined in the docsGatehouse
@Gatehouse I tried this out. I am not sure why this is not working for me. I am using Ionic Framework to build a hybrid app. When I set the origin to example.com. All features related to Iframe freezes.Quillet
Q
4

Are you getting the error on all videos from VEVO? Are you sure the video you're trying to play is embeddable? Add the 'videoEmbeddable' parameter with the 'true' value so you're only working with videos you can embed.

The videoEmbeddable parameter lets you to restrict a search to only videos that can be embedded into a webpage. If you specify a value for this parameter, you must also set the type parameter's value to video.

Acceptable values are: any – Return all videos, embeddable or not. true – Only retrieve embeddable videos.

source: https://developers.google.com/youtube/v3/docs/search/list#videoEmbeddable

Quach answered 3/5, 2015 at 18:42 Comment(0)
A
0

For Swift 4.2 of @JAL's answer you just need to do the following and it will work like a charm with vevo videos:

import UIKit
import youtube_ios_player_helper

class MyYoutubePlayerViewController: UIViewController {

  @IBOutlet weak var playerView: YTPlayerView!

   private var playerVars: [String : Any] =  [ 
                                                "playsinline" : 1,
                                                "showinfo" : 1,
                                                "rel" : 1,
                                                "modestbranding" : 1,
                                                "controls" : 1,
                                                "origin" : "https://www.youtube.com" ]

  override func viewDidLoad() {
     super.viewDidLoad()

     self.playerView.load(withVideoId: "YQHsXMglC9A", playerVars: playerVars)
  }

}
Armand answered 28/5, 2019 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.