I am trying to detect when an AirPlay device is available on the network and if there is one, I'd like to display a list.
For example, the app "Dailymotion" does exactly what I want : when I connect my iPhone to a network with an Apple TV, an "AirPlay" icon appears : https://dl.dropbox.com/u/4534662/Photo%2004-03-13%2010%2007%2014.png (just next the HD)
And then, when clicking on the AirPlay icon, a picker shows up with the available AirPlay devices : https://dl.dropbox.com/u/4534662/Photo%2004-03-13%2010%2007%2018.png
I didn't find a way to do that with Apple Documentation. So, how can I do that programmatically?
You can display an AirPlay picker view (if AirPlay is available) like so:
MPVolumeView *volumeView = [ [MPVolumeView alloc] init] ;
[volumeView setShowsVolumeSlider:NO];
[volumeView sizeToFit];
[view addSubview:volumeView];
The MPVolumeView displays all the available AirPlay devices. The code above disables the volume slider, which you may or may not want to do. What you can't do is get programatic access to AirPlay device information.
Related
I have a video application in which I am using Airplay to stream the video. I am using the below code.
let airView: MPVolumeView = MPVolumeView()
airView.showsRouteButton = true
airView.showsVolumeSlider = true
airView.sizeToFit()
airView.tintColor = UIColor.black
airView.autoresizingMask = UIViewAutoresizing.flexibleWidth
airplayButton = UIBarButtonItem(customView: airView)
airplayButton.tintColor = UIColor.white
self.navigationItem.setRightBarButtonItems([airplayButton], animated: true)
Using the code below, I can see the Airplay picker button, I can also see the volume slider however when I am connecting the airplay, the volume button disappears so our clients can not make volume up and down using the phone hardware button.
Is there a way to have either to prevent the disappearance of that button or support hardware volume support while playing Airplay?
Additional info:
When using older AirPlay devices such as an old AppleTV that users AirPlay1 the volume controls should work. However, when the same app is connected to an AirPlay2 device, the volume controls are removed. And in fact the data screen for the MPVolumeSlider is removed. The slider will return when connected back to the Phone or Bluetooth speakers.
Recently Apple deprecated the Router Button on MPVolumeView starting with iOS 13 and this new router view does not include a volume slider. It appears that Apple wants us to use either the rocker, airplay mirroring or the volume controls that the AVRouterView holds. This change becomes very confusing to the user as sometimes the slider is there and sometimes it isn't. Even if the slider is shown disabled with another slider, the user does not understand why they can use the rocker and sliders in the AVRouterView and not on the app itself with AirPlay2. They also don't even understand what AirPlay1 vs AirPlay2. Things such as metadata even work differently.
I am trying to do airplay with apple TV. I found out that when I just play video with avplayer without mirroring, I can still play with full screen. However, screen count is only 1 (which is for iPad).
If I do mirroring, the screen count is 2 (one is iPad and one is external monitor). I think without mirroring, screen count should be two also. I am confusing about that. I would like to know more about difference between airplay mirroring vs without mirroring
screens = [UIScreen screens]; //to count screen
The difference is simple.
Mirroring will duplicate everything on your screen and display it on another screen. This is used for things like showing off a photo gallery to a group of people or something like this.
If Mirroring is turned off then this will act as an external display. This is used in games like Real Racing 3 where you can play the game on a TV or something and use your iPhone (iPad) as a controller for the game. The TV and the iPhone will have different things on their screens.
Feel like chiming in as Fogmeister's answer is not all that accurate.
You can easily use mirroring AND have different content on the Apple-TV screen. It is, as far as I've been able to find out, the only way that is supported by any of Apple's public APIs at the moment. A solution has been detailed here among other places.
The idea is to hijack the external window and then give it a viewController which you control (like any other):
if([[UIScreen screens] count] > 1){
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
_secondWindow = [[UIWindow alloc] initWithFrame:secondScreen.bounds];
self.secondWindow.screen = secondScreen;
_externalViewController = [[YourExternalViewControllerClass alloc] init];
self.secondWindow.rootViewController = self.externalViewController;
self.secondWindow.hidden = NO;
}
In the above example the _secondWindow and _externalViewController instances are properties of the viewController setting up the device view.
Hi i am building iOS application target iOS 5 and above. I am using MPMoviePlayerController to stream movie file. I that player i want to give airplay support.
According to apple documentation
Default Movie players (iOS 4.3 and later) support wireless movie
playback to AirPlay-enabled hardware such as Apple TV. The movie
player presents a control that allows the user to choose
AirPlay-enabled hardware for playback when such hardware is in range.
It seems that by default it will display airplay button in fullscreen mode if any airplay device is in range. But it is not seems to be happening. I am unable to see airplay button in movie player.
Am i missing something? Please advise.
By default, MPMoviePlayerController enables AirPlay support. If you haven't set it as FALSE. Then, probably you need to check your network or AppleTV's network connection. They need to be in same network (intranet usually).
There is a safe way to detect whether your iOS device is able to find AppleTV. You can double click HOME button, swipe task bar from left to right side, if you can see "Airplay" route button, then you can reach it. Otherwise, you need to check your AppleTV setting to make sure Airplay function is enabled and AppleTV is connected to same network that you iOS device in.
If you are using your own customized video play controller interface, you can embedded the "Airplay" button into your own UI.
MPVolumeView
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.
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.