繁体   English   中英

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

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

我正在使用 objective-c 制作 iOS 应用程序。
请告诉我如何在 iOS13.x 环境中修复 AVPlayerView。

ViewController.m 写

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

VideoView 包含 AVPlayerView

AVPlayerView.m 写

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

@implementation AVPlayerView

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

@end

由于某种原因没有调用 layerClass 方法。
此外, (AVPlayerLayer *) self.videoView.layer 返回的 class
AVPresentationVontainerViewLayer。
我想要一个 AVPlayerView class。
我应该如何解决?

尝试这个:

    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 版本:

 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