My iPad application plays videos through the built-in AVplayerViewController. When I mirror the application on the Apple TV, the video appears only on the TV screen and goes to full screen. The built-in player displays the following message: “TV Connected. This video plays on the TV.
Apple's documentation does not talk about this behavior, except that when playing on both devices, playback should play on both devices. And AVPlayer settings, such as 'allowExternalPlayback = NO', have no effect.
How to keep mirroring an application while playing embedded video using AVPlayer?
#import <AVKit/AVKit.h>
#import "myVC.h"
#import "VideoPlayer.h"
@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];
}
#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];
}