gpt4 book ai didi

ios - 查找与 AVPlayerItem 关联的 AVPlayer

转载 作者:技术小花猫 更新时间:2023-10-29 10:17:06 29 4
gpt4 key购买 nike

一个 AVPlayerItem 只能分配给一个 AVPlayer。将 AVPlayerItem 添加到 AVPlayer 后,将来尝试将其添加到不同的 AVPlayer 时将对应用进行 SIGABRT。

那么,给定一个 AVPlayerItem,您如何确定:

  1. 它当前与哪个 AVPlayer 相关联?和
  2. 它是否曾在过去的任何时候被插入到 AVPlayer 中?

下面的代码可靠地演示了这个问题:

AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
AVPlayer *firstPlayer = [[AVPlayer alloc] init];
[firstPlayer replaceCurrentItemWithPlayerItem:item];
AVPlayer *secondPlayer = [[AVPlayer alloc] init];
[secondPlayer replaceCurrentItemWithPlayerItem:item];

这是错误信息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'

最佳答案

有一种半合法的方式在未来可能会失效。播放器项目有一个名为 _player 的私有(private)方法(而且似乎是变量)。您可以像这样查询它(技术上不使用私有(private) API,所以我认为它应该是 AppStore 安全的):

id player = [item valueForKey:@"_player"];

关于ios - 查找与 AVPlayerItem 关联的 AVPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12611120/

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