-[AVPlayerViewController retain]: 发送到释放实例的消息

-[AVPlayerViewController retain]: message sent to deallocated instance

我正在尝试将 AVPlayerViewController 添加到聊天气泡中,以便收到的任何音频或视频消息都可以直接在聊天气泡中播放。我的 UITableView 列表包含许多这样的气泡。但是当我尝试滚动 table 视图时,应用程序崩溃并显示 -[AVPlayerViewController retain]: message sent to deallocated instance.

下面是我向每个聊天气泡添加 AVPlayerViewController 对象的代码:-

_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:url];
_playerViewController.view.frame = CGRectMake(10.0, 5.0, 190.0 , 90.0);  //   self.view.bounds;
_playerViewController.showsPlaybackControls = YES;

[_playerViewController.view setTranslatesAutoresizingMaskIntoConstraints:YES];
[_playerViewController .view setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
[cell.contentview addsubview:_playerViewController.view];

url 包含文件路径 (audio/video),我试图将 _playerViewController 对象添加到 UITableView 单元格的内容视图,但它抛出以上错误。谁能告诉我我应该做什么。

每个单元格不应包含 AVPlayerViewController。太可怕了!

你应该管理你的东西,就像每个单元格只显示你的视频的缩略图一样,你应该管理 url 的视频数组。现在使用普通 AVPlayerViewController 播放任何视频。我的意思是当用户点击单元格或单元格的播放按钮然后将 url 传递给播放器并播放视频时!!