简体   繁体   中英

Cannot get AVPlayerLayer on iOS13.x by Objective-C

I'm making an iOS app with objective-c.
Please tell me how to fix AVPlayerView in iOS13.x environment.

ViewController.m write

AVPlayerLayer* layer = (AVPlayerLayer*)self.videoView.layer;

VideoView contains AVPlayerView

AVPlayerView.m write

#import "AVPlayerView.h"
#import <AVFoundation/AVFoundation.h>

@implementation AVPlayerView

+(Class)layerClass{
    return AVPlayerLayer.class;
}

@end

The layerClass method is not called for some reason.
Also, the class returned by (AVPlayerLayer *) self.videoView.layer
AVPresentationVontainerViewLayer.
I want an AVPlayerView class.
How should i fix it?

Try this:

    NSURL *url = [NSURL fileURLWithPath:path];
    AVPlayer *player = [AVPlayer playerWithURL:url];
    AVPlayerViewController *AVPlayerVc = [[AVPlayerViewController alloc] init];
    AVPlayerVc.player = player;
    if (AVPlayerVc) {
        [self presentViewController:AVPlayerVc animated:YES completion:^{
            [player play];
        }];
    }

Swift Version:

 let player = AVPlayer(url: YOUR_URL)
 let playerController = AVPlayerViewController()
 playerController.player = player
 present(playerController, animated: true) {
         player.play()
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM