Adding subtitles to AirPlay video using AVFoundation on iOS? - 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.

Related

Is there any way to hide the video controls from Notification Center on iOS 11.0?

In my app, I play a video from a WebView and I don't want to allow the users to stop the video, so I don't show any video control. But the controls still appear in NSNotification and in Control Center. Is there any way to hide them?
WebView core functions are handled by the OS, so i think its not possible but you should implement the video/audio handling natively using these classes:
MPNowPlayingInfoCenter (currenlty playing items)
MPRemoteCommandCenter (observe different events, play/pause/next.. )

iOS 7 Dev - Minimizing app causes UIWebView inline YouTube Player to stop playing

I'm working on a project that plays YouTube videos, inline in a UIWebView. What I'm trying to do is to continue playing the app's audio, even when the home button is pressed (or focus is off the app in any way). I've done the following (as suggested from searching my question here):
Made sure Audio and Fetch were included in my info.plist for Background Modes
Made sure my ViewController that contained the WebView is registered to receive remote control events:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
Messed with the AVAudioSession (sharedSession) and set the category to playback.
None of these things worked. Either I'm doing one of them incorrectly (which I doubt--I've found several "solutions" here that have worked for other people but not for my particular case).
I have a feeling this might have something to do with the way the WebView plays audio. Any ideas?
You need to add BackgroundMode: "Audio And AirPlay".
It's the following key in your plist:
`<key>UIBackgroundModes</key>
<array>
<string>audio</string>`

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.

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

iPhone SDK: Custom video player controls

In my iPhone app I have designed a custom video player, currently it is very basic with just a play pause and stop button,
but I would like the user to be able to scrub, (I think thats the right word) the video like you can do with apple's original media player.
So for Instance I would like to be able to take a UISlider and have it control the current postiion of the videos playback if you get what I mean. Oh and incase your curious, the way I pause/play/stop the video is by using this simple piece of code [self.theMovie play]; [self.theMovie stop]; [self.theMovie pause]; The trouble is I don't know how to scrub the video.
Any help appreciated.
I've asked the same question: customize quicktime iphone and here MPVideoPlayer add/remove buttons
It seams that you have to posibilities:
You can add you view over the main window. An sample can be found here: MoviePlayer Sample
You can iterate through views, found one you need and Add/Remove views. I don't know yet how must does Apple likes/dislikes this method.

Resources