简体   繁体   English

无法通过 Objective-C 在 iOS13.x 上获取 AVPlayerLayer

[英]Cannot get AVPlayerLayer on iOS13.x by Objective-C

I'm making an iOS app with objective-c.我正在使用 objective-c 制作 iOS 应用程序。
Please tell me how to fix AVPlayerView in iOS13.x environment.请告诉我如何在 iOS13.x 环境中修复 AVPlayerView。

ViewController.m write ViewController.m 写

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

VideoView contains AVPlayerView VideoView 包含 AVPlayerView

AVPlayerView.m write AVPlayerView.m 写

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

@implementation AVPlayerView

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

@end

The layerClass method is not called for some reason.由于某种原因没有调用 layerClass 方法。
Also, the class returned by (AVPlayerLayer *) self.videoView.layer此外, (AVPlayerLayer *) self.videoView.layer 返回的 class
AVPresentationVontainerViewLayer. AVPresentationVontainerViewLayer。
I want an AVPlayerView class.我想要一个 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: Swift 版本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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