iosobjective-cretainavplayerviewcontrolleruibubbletableview

-[AVPlayerViewController retain]: message sent to deallocated instance


I am trying to add an AVPlayerViewController to a chat bubble so that any audio or video messages when received can be directly played in the chat bubble. My UITableView list contains many of these bubbles. But when I try to scroll the table view, the app gets crashed showing -[AVPlayerViewController retain]: message sent to deallocated instance.

Here below is my code for adding a AVPlayerViewController object to each chat bubble :-

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

the url contains the file path (audio/video), and I am trying to add the _playerViewController object to UITableView cell's content view, but it throws the above error. Can anyone please tell me what I should be doing.


Solution

  • Every cell should not contain AVPlayerViewController. It's horrible!

    You should manage your stuff like every cell just display thumbnail of your video and you should manage array of urls of videos. now use common AVPlayerViewController to play any video. I mean when user tap cell or play button of cell then pass that url to player and play video!!