How to play YouTube video in iOS not in fullscreen? - ios

I've been trying to get YouTube music videos to play in my iOS app in a small window (not full screen) and can't get it to work. I've tried the following:
I first used the YouTube API and created a YTPlayerView as instructed here: https://developers.google.com/youtube/v3/guides/ios_youtube_helper#adding_ytplayerview. This allowed me to play videos in-line, but many videos were unable to be played because of licensing issues, stating "This video contains content from *. It is restricted from playback on certain sites."
I then tried using a UIWebView, which successfully played the music videos that were previously unavailable. However, these videos were always forced to play in fullscreen mode, even when I set webView.allowsInlineMediaPlayback = YES;
I also tried embedding the video using the technique discussed here: How to embed YouTube video on iOs and play it directly on UIWebview without full screen. This worked to keep videos inline, but again, rendered certain videos unplayable.
I finally tried using an MPMoviePlayerController, but later found out that it can't actually play YouTube videos, as we don't have access to the direct links of video files, so this was another no-go.
Apps like PingTune were clearly able to figure this out using YouTube - they are able to play YouTube music videos in a custom, non-fullscreen view and without ads - what am I missing? Is there a part of the YouTube API that allows me to play these music videos that I implemented incorrectly?

I've never tried it myself but you could try LBYouTubeView by Laurin Brandner. LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController. You even have the choice between high-quality and standard quality stream.
Code sample
LBYouTubePlayerViewController* controller = [[LBYouTubePlayerViewController alloc] initWithYouTubeURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=1fTIhC1WSew&list=FLEYfH4kbq85W_CiOTuSjf8w&feature=mh_lolz"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
controller.view.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
controller.view.center = self.view.center;
[self.view addSubview:self.controller.view];

Related

URL syntax for Youtube videos in fullscreen WITHOUT embedding video

I like to be able to share youtube music video URLs that automatically start in full-screen. The only way I know how to do this is by sharing the video as an embedded video; such as:
https://www.youtube.com/embed/oRdxUFDoQe0?autoplay=1
Unfortunately, as you can see, that does not work on copyrighted videos. So.. what's the trick to playback youtube videos automatically in fullscreen without embedding it? I tried the below URL format, but that didn't work either. Surely there has to be a way to do this>
https://www.youtube.com/watch?v=oRdxUFDoQe0&fs=1

Playing Vimeo Videos with Custom Video Player in iOS

I have to play Vimeo videos in my iOS application using a video player. I need to log events like play, pause, seek etc. Its not possible to play using MPMoviePlayerController or AVPlayer as Vimeo videos have flash content. I am able to play using UIWebView. But, it is showing default Vimeo player controls. I need to have my own controls to play, pause etc as I need to log those events.
I have tried for lot of solutions. Nothing worked. If anyone knows how to play Vimeo videos using custom player. Please Let me know.
I am able to find out solution for this problem. I have used YTVimeoExtractor present here.
Its README.md file says following :
YTVimeoExtractor helps you get mp4 urls which can be use in iOS's native player. You can even choose between mobile, standard and high definition quality.
YTVimeoExtractor doesn't use UIWebView which makes it fast and clean.
I have used MKMoivePlayerViewController and its notifications - MPMoviePlayerPlaybackStateDidChangeNotification and ˚ notifications to get stop, pause events.
The only official way to use a player besides the Vimeo player to play Vimeo videos is to use third-party player urls provided to PRO members: https://vimeo.com/s/adg

How to display overlay on Apple TV via AirPlay

I am developing an iOS app that displays a video, e.g., a football game, on Apple TV via AirPlay. I want to display additional information, e.g., player stats, on the big screen while the video is playing.
I am aware of the Redfin approach, where they require the user to turn on AirPlay mirroring first. Unfortunately, this is not acceptable for us. We want it to be obvious to users on how to show the video.
We are currently presenting an AirPlay Route button before displaying the video to allow the user to set it up using the following code.
self.airPlayPicker = [[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
self.airPlayPicker.showsVolumeSlider = NO;
self.airPlayPicker.showsRouteButton = YES;
[self.view addSubview:self.airPlayPicker];
The Route button will show when there is an Apple TV around, allowing the user to turn it on. We then present the video with MPMoviePlayerController.
When AirPlay is turned on and the video is playing, in code, I see only one UIScreen, but two UIWindows. But both UIWindows have the same dimensions as the iPhone. When I add a subview to either UIWindow, the subview always shows up on the iPhone.
Has anyone figured out how to present an overlay on top of the video on Apple TV? How do I even find the view object where the video is hosted?
I am aware that MPMoviePlayerController is built on top of AVPlayer. Would using AVPlayer give us better control of the UI?
As far as I know, this shouldn't be possible. When using AirPlay without mirroring, only the URL of the video is sent to the Apple TV. It is then up to the Apple TV to actually play the media.
Mirroring is the way to do it.

Playing youtube videos on iOS

I was wondering how are apps like McTube (https://itunes.apple.com/us/app/mctube-for-youtube/id559618284?mt=8) playing youtube videos. It looks like a custom MPMoviePlayerController but is that allowed?
BTW I need autoplay which I couldn't achieve with UIWebView, that's why i was wondering.
Some YouTube videos can be played back in a MPMoviePlayerController - some cannot. When you query a video through the YouTube Data API (link here) you'll get back all the content types available for a particular videos, including the Flash player, 3GPP, MP4 (if available), etc. You can use these URLs to load up a MPMoviePlayerController.
This is perfectly fine, but as I've said - not all videos are available to embed this way. Some videos (mainly ones that require adverts to be displayed) can't be put into native controllers.

How to play youtube video without UIWebView or detect video player when youtube video start playing using webview?

I need to play youtube video in my iOS application and while video is playing I need to add an overlay on video.
1.Now how can i run youtube video in native player?
2.if I play video in UIWebview then how can i detect that video is
playing and how to add overlay on the video?
MPMoviePlayerViewController cannot directly play youtube video urls.You need to extract the url before loading MPMoviePlayerViewController with the url.
you can see a working demo in my github repo:
Try this::
https://github.com/DpzAtMicRO/IOSYoutubePlayer
LBYoutubeExtractor extracts the youtube Url with JSON.
Please do read the README.md before you use this in your application.
Regards
MPMoviePlayerViewController is a good one but last commit is years ago. I found another solution called 'XCDYouTubeKit' which supports iPhone/iPad and iOS7 onwards with full screen YouTube video.
You can access github page at here and fully documented tutorial at here
This is what official developer says in his page:
The only official way of playing a YouTube video inside an app is with a web view and the iframe player API. Unfortunately, this is very slow and quite ugly, so I wrote this player to give users a better viewing experience.

Resources