Question

I have an app with a news feed screen, like the one in the facebook app. For this, I have made a custom cell, which has a contentView which is a UIView. This contentView gets initialized for displaying text, an image or video. This is done in the class for the custom cell. For the video, I'm trying to add MPMoviePlayerViewController as a subview to the cell's contentView:

MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:nil];
player.view.frame = self.contentView.frame;
player.view.tag = kVideoView;
[self.contentView addSubview:player.moviePlayer.view];

Then, when I load that cell in the tableviewcontroller, I want to give it contentURL, like this:

MPMoviePlayerViewController *controller = (MPMoviePlayerViewController *)[cell viewWithTag:kVideoView];
controller.moviePlayer.contentURL = [NSURL URLWithString:postInfo.uri];
return;

This crashes the app with an error:

-[MPMovieView moviePlayer]: unrecognized selector sent to instance

How do I fix this?

Was it helpful?

Solution

As you are adding player.moviePlayer.view to content view.

So while retrieving you will get reference to player.moviePlayer.view only not MPMoviePlayerViewController.

My suggestion is don't create multiple MPMoviePlayerViewController instance. You can add some UIButton or UIImageView on cell with snapshot of particular video. And while playing only you can create MPMoviePlayerViewController instance and play your video

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top