YouTube embed AirPlay UIWebView - ios

I am developing a video application which contains a lot of video from different sources. One of the options in the application has to be to play videos through airplay on a TV.
For displaying YouTube video in my application I am using YTPlayerView, which is an objective-C helper for the YouTube API.
My question is: is there an option or param I can pass so the YouTube video can also be played through Airplay? I couldn't find anything useful on Internet.

In - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams in YTPlayerView.m (line 617), add:
self.webView.mediaPlaybackAllowsAirPlay = YES;
right before you return YES.

Related

Will plays via YouTube API register as plays on the site?

This is a fairly basic question I think. If a site uses the YouTube API to embed videos on it, will plays to that video also register as plays on the YouTube site itself, or are those plays only counted for people that actually play the video on YouTube.com?
I searched through google and Youtube docs, but didn't see anything relevant, but I could have missed seeing it.
They would count as normal plays via YouTube website if you use official IFrame player API for embedding.
Note: A playback only counts toward a video's official view count if
it is initiated via a native play button in the player.
However, note if autoplay is enabled, views will not increase.
See here: Embedded youtube video with "autoplay=1". Does it count towards views?.

AVPlayer can't play Vevo Youtube video

I'm developing my youtube app on iOS and using AVPlayer to play video. But I don't know why my player can't play the Vevo video. Any idea for my problem? Thanks a lot.
You should use the iOS Youtube Helper library for playing youtube videos.
https://developers.google.com/youtube/v3/guides/ios_youtube_helper
I don't know if you can use the AVPlayer. I've seen some examples using MPMoviePlayerController on CocoaControls, like this one: https://www.cocoacontrols.com/controls/hcyoutubeparser or this one: https://www.cocoacontrols.com/controls/xcdyoutubevideoplayerviewcontroller
But I don't think using youtube's url directly in your player fits the ToS of the platform. So I will recommend you tu use the Youtube Helper Library if you are planning to publish your app.

Video restricted from playback on certain sites, even though embed is allowed

I am creating an iOS app that uses the youtube iOS player helper. It works fine, but for some videos, when trying to play them, I get 'This video contains content from [YYY]. It is restricted from playback on certain sites'.
The metadata for one of the videos that doesn't work is here: http://gdata.youtube.com/feeds/api/videos/KJB49SAHIKM?v=2&prettyprint=true.
And http://gdata.youtube.com/feeds/api/videos/dRgPi1OPBeA?v=2&prettyprint=true is the metadata for a video that works.
The embed permission seems to be the same. What could the problem be? Is there something I'm missing?
I know that 'syndicate' is denied for the video that doesn't work, but I also have a video with syndicate and embed allowed that doesn't play and gives the same error, so I assume there must be something else.
Also, I have access to the channels that uploaded those two videos. Are there any settings for the individual videos that have to be set for them to be able to be embedded?
Add player vars while initializing youtube sdk:
NSDictionary *playerVars = #{
#"origin" : #"http://www.youtube.com",
};
[self.playerView loadWithVideoId:#"KOvoD1upTxM" playerVars:playerVars];
Enjoy!
I had the same issue but it seems like its due to the fact that publishers have restricted the video to be played outside youtube.com. If you own the channel and videos then probably you have a setting that restricts playback of videos outside youtube. For other videos that I dont have access to I put an option to watch it on youtube that would fire up native youtube app with the video loaded.

Can we PLay Youtube audio only inside app?

I am working on an app, where I am required to play the youtube's Audio and Video as well.
I am able to PLay video Using "XCDYouTubeVideoPlayerViewController" available on cocoa controls. (I am getting Youtube url from the backend)
Is there any way , where I can play audio also only inside my app. Because I checked over Internet and stackoverflow, but Couldn't find anything working.
And Is there any way, where the Video or audio can be played at the Back gorund , i.e when I press Home button the vidoe/audio keeps on playing.
All I fund on stack overflow is, that its forbidden, and the chances are your app will be blocked.
Please help, Thanks Again.
Youtube doesn't encourage audio only! here's what they have to say about this.
Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to: "separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API" -Kuan Yong, YouTube API Team
However there's a hacky workaround workaround whereby you can use a hidden UIWebView and play in that.

How to play just the audio of YouTube Video?

In my app I have played a youtube video by embedding it, but how can i only play the audio of the video? I tried using AVAudioPlayer and use the videos url as the file path but it didnt work, any help?
No it is not possible, only one workaround is just to use a hidden UIWebView and play in that.
Youtube forbids playing audio only! here is the message from youtube
Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to: "separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API"
-Kuan Yong, YouTube API Team

Resources