gpt4 book ai didi

ios - 创建 AVPlayerLayer 会导致模拟器崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:32:11 25 4
gpt4 key购买 nike

我有一个类在回调中返回 AVPlayer 和 AVSynchronisedLayer。当我使用 AVPlayer 初始化 AVPlayerLayer 时,我崩溃了(只发生在模拟器中)。代码如下所示:

  self.projectPlayer = [[MYMobilePlayer alloc] init];
[self.projectPlayer setDelegate:self];
[self.projectPlayer returnPlayerForProjectScene:self.projectScene andCallback:^(NSError *error, AVPlayer *player, AVSynchronizedLayer *syncLayer) {


self.syncLayer = syncLayer;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
NSLog(@"%@",playerLayer); // Also crashes if I assign to private member variable
// More code that uses the playerLayer - not needed to illustrate the problem

}];

回调中返回的对象是正确的,所以我认为我不需要显示创建和返回它们的代码。

堆栈跟踪如下所示(不是很有帮助)。

enter image description here

知道这里会发生什么吗?

最佳答案

UIKit 代码应始终在主线程上调用。您的 returnPlayerForProjectScene 回调发生在其他视频处理线程上。将有问题的代码分派(dispatch)到主队列应该可以解决您的崩溃问题:

[self.projectPlayer returnPlayerForProjectScene:self.projectScene andCallback:^(NSError *error, AVPlayer *player, AVSynchronizedLayer *syncLayer) {

dispatch_async(dispatch_get_main_queue(), ^{

self.syncLayer = syncLayer;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
NSLog(@"%@",playerLayer); // Also crashes if I assign to private member variable
// More code that uses the playerLayer - not needed to illustrate the problem

});
}];

关于ios - 创建 AVPlayerLayer 会导致模拟器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40417413/

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