Playback restricted on iOS for VEVO videos from YouTube API

后端 未结 3 1605
情书的邮戳
情书的邮戳 2021-02-20 11:14

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 fol

相关标签:
3条回答
  • 2021-02-20 11:25

    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

    0 讨论(0)
  • 2021-02-20 11:38

    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

    0 讨论(0)
  • 2021-02-20 11:45

    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)
      }
    
    }
    
    0 讨论(0)
提交回复
热议问题