My iPad app plays video via an embedded AVplayerViewController. When I mirror the app to an Apple TV, the video appears only on the TV and takes over the full screen. The embedded player shows the following message: "TV Connected. this video is playing on the TV.
Apple documentation is silent on this behavior, other than claiming video should play on both devices during mirroring. And AVPlayer settings such as 'allowsExternalPlayback=NO' have no effect.
How can I retain the app mirroring while playing embedded video with the AVPlayer?
#import <AVKit/AVKit.h>
#import "myVC.h"
#import "VideoPlayer.h"
// video handlers
@property (weak, nonatomic) IBOutlet UIView *videoView;
@property IBOutlet AVPlayerViewController *videoVC;
@end
@implementation myVC
- (void)viewDidLoad {
[super viewDidLoad];
[self.videoView addSubview: videoVC.view];
[VideoPlayer loadVideo:videoUrl inVC:self.videoVC];
}
// video methods in custom VideoPlayer class
#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface VideoPlayer : NSObject
@property (nonatomic) AVPlayer *player;
@property (nonatomic) AVPlayerViewController *videoVC;
+(void)loadVideo:(NSString*)name inVC:(AVPlayerViewController*)videoVC;
#import "VideoPlayer.h"
@implementation VideoPlayer
+(void)loadVideoURL: inVC:(AVPlayerViewController*)videoVC;
{
[self playVideo:url inVC:videoVC];
}
+(void)playVideo:(NSURL*)videoFileUrl inVC:(AVPlayerViewController*)videoVC;
{
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:videoFileUrl];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
videoVC.player = player;
[player play];
}