4

我的 iPad 应用通过嵌入式 AVplayerViewController 播放视频。当我将应用程序镜像到 Apple TV 时,视频仅出现在电视上并占据全屏。嵌入式播放器显示以下消息:“电视已连接。此视频正在电视上播放。

Apple 文档对此行为保持沉默,只是声称视频应在镜像期间在两台设备上播放。而 'allowsExternalPlayback=NO' 等 AVPlayer 设置无效。

如何在使用 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];
}
4

0 回答 0