gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:01:45 24 4
gpt4 key购买 nike

我正在用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返回的类
AVPresentationVontainerViewLayer。
我想要一个AVPlayerView类。
我该如何解决?

最佳答案

试试这个:

    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];
}];
}

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

关于ios - 无法通过Objective-C在iOS13.x上获得AVPlayerLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58235211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com