How to display overlay on Apple TV via AirPlay - ios

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.

Related

How to play YouTube video in iOS not in fullscreen?

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];

How do I remove the airplay from a video player for the ipad?

So I have this player that I am using to video locally. I need to be able to mirror airplay the screen to a tv but every time I set airplay to mirror the player just sends the whole video to the screen instead of just mirroring.
https://github.com/NOUSguide/NGMoviePlayer
I contacted the developers about how to disable the airplay part of it. They told me to remove the airplay layer from the player. Can someone lead me into the right direction into getting this done?
If you want to disable AirPlay, just set the allowsAirPlay property to false in your MoviePlayerController object.
You can access the mirrored screen by using this method :
UIScreen * screen = [[UIScreen screens] objectAtIndex:1];
before calling this method, ensure that the screens property has more than one object

Adding subtitles to AirPlay video using AVFoundation on iOS?

Is there any way to make subtitles show over AirPlay on iOS using av AVPlayer with anAVPlayerItem? I've currently implemented subtitles by adding labels to the view hierarchy which works fine in the app, but that obviously doesn't work with AirPlay.
So, is there any way to display subtitles over AirPlay using AVFoundation?
You mentioned that you already implemented your own CC by creating a view for CC and adding it on top of the video. It will be easier to use AirPlay mirroring. You can do this by detecting an external screen and then place the content on it.
// detecting an external screen
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myExternalScreenDetected:) name:UIScreenDidConnectNotification object:nil];
//
// Grab external screen then add the content
- (void)myExternalScreenDetected:(UIScreen *)externalScreen {
UIWindow *window = [[UIWindow alloc] initWithFrame:externalScreen.bounds];
// ...add content to the window...
window.screen = externalScreen;
window.hidden = NO;
}
Another option is to use native closed caption.This can be done by adding language files (WebVTT format) into the m3u8 playlist. I haven't tried this. It seems more complicated. You can take a look at the Apple's video here: https://developer.apple.com/videos/wwdc/2012/?id=512
Mirroring feature seems easier to implement CC than the native way. However the native video airplay has better performance because the AppleTV loads the playlist file (m3u8) and plays the content directly. Mirroring AirPlay has to re-compress the output and send to AppleTV.
You've probably already figured this out, but the reason your closed-captions aren't displaying when you airplay to Apple TV is probably that your AppleTV has closed captioning turned off.

Purpose of mediaPlaybackAllowsAirPlay property on UIWebView

The UIWebView Class Reference describes mediaPlaybackAllowsAirPlay as follows:
A Boolean value that determines whether Air Play is allowed from this view.
When the mediaPlaybackAllowsAirPlay is set to YES:
If on my iPad I load a YouTube or Vimeo video to a UIWebView with this set to it's default value of YES and play the video while mirroring to an AirPlay device, the video signal is sent to the AirPlay device and takes over the AirPlay device screen and "TV Connected / This video is playing on the TV" is displayed in the UIWebView on the AirPlay. This is the behavior I would expect.
When the mediaPlaybackAllowsAirPlay is set to NO:
I get exactly the same behavior as above. What I expected is that if the UIWebView mediaPlaybackAllowsAirPlay was set to NO, that instead of sending the video signal to the AirPlay device, even if the iPad is mirroring, the video would simply play inside the UIWebView on the iPad.
Has anyone used this property to create two different functional behaviors and what were they?
As far as I can tell, this property has no impact on the playing of AirPlay media.
It appears that the mirroring mode is taking precedence over the mediaPlaybackAllowsAirPlay flag.
If I'm interpreting the documentation correctly, mediaPlaybackAllowsAirPlay only allows the user to send the data to a particular airplay compatible device. If it is disabled, the airplay selector simply doesn't show up.
If this is a bug to you, please head over to http://bugreporter.apple.com and let Apple know.

Set Airplay manually?

I have an iPad app and I have a video playing in a view. I would like to play video using Airplay but by pressing my own button.
I have set allows airplay = YES and so forth, this works if I enable the full controls, but I want to set no controls and have my own button to play the video using Airplay.
So far, I have found no information that would allow me to play a video on AppleTV without allowing the normal controls.
So just using an UIButton action to force the airplay, or at least get available devices and set it manually. Anything that would allow me to do this.
MPVolumeView will only control audio, it won't control video. For that you'd need iOS 5's AVPlayer, or a movie controller.
An alternative for you might be to use AirplayKit, a 3rd party library.
https://github.com/rothacr/AirplayKit
To answer my own question.
This is quite possible without jailbreak.
Here is apple's own page explaining this, so this will pass the review process.
Apple developer library document explaining how to do this

Resources