4

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];
}
Brendenw
  • 785
  • 1
  • 6
  • 22
  • I'm starting to think the only way to go is to manually re-create the main UIWindow and point it to the second UIScreen. I assumed there would be a flag or setting on the Player to indicate if it should be the sole view on the secondary display, but I cannot find it. Have you been able to find anything? – jeffro37 Sep 15 '15 at 15:09
  • I am having this issue as well. It seems that the issue happens on iOS 8 devices, but iOS 9 devices mirror the video properly. Has anyone found a solution? – tboyce12 Dec 02 '15 at 02:14

0 Answers0