AVPlayer添加电影进行查看

时间:2016-03-16 11:02:11

标签: ios avplayer

假设下面的代码,我将如何在movieView中显示mov?我是否需要以这种方式对AVPlayer进行子类化,或者是否有更简单的方法来实现这一目标?

UIView *movieView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 1080)];
movieView.backgroundColor = [UIColor redColor];
[self.view addSubview:movieView];

NSURL *url = [[NSBundle mainBundle]URLForResource:@"Clock_stroke_04_Full" withExtension:@"mov"];
self.player = [AVPlayer playerWithURL:url];
[self.playerView setMovieToPlayer:self.player];
[self.player play];
    @implementation AVPlayerClass

    + (Class)layerClass
    {
        return [AVPlayerLayer class];
    }

- (AVPlayer*)player
    {
        return [(AVPlayerLayer*)[self layer] player];
    }

    -(void)setMovieToPlayer:(AVPlayer *)player
    {
        [(AVPlayerLayer*)[self layer] setPlayer:player];
    }
    @property (nonatomic, retain) AVPlayer *player;
    @property (nonatomic, retain) AVPlayerClass *playerView;

1 个答案:

答案 0 :(得分:2)

RInside.h

请尝试运行此代码。谢谢