自定义单元格中的MPMoviePlayerViewController

时间:2013-12-19 09:31:46

标签: ios uitableview mpmovieplayercontroller subview

我有一个带有新闻Feed屏幕的应用,就像facebook应用中的那个。为此,我创建了一个自定义单元格,其contentViewUIView。此contentView被初始化以显示文本,图像或视频。这是在自定义单元格的类中完成的。对于视频,我试图将MPMoviePlayerViewController作为子视图添加到单元格的contentView中:

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

然后,当我在tableviewcontroller中加载该单元格时,我想给它contentURL,如下所示:

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

这会导致应用程序崩溃:

-[MPMovieView moviePlayer]: unrecognized selector sent to instance

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

正在向内容视图添加player.moviePlayer.view

因此,在检索时,您将只能player.moviePlayer.view引用MPMoviePlayerViewController

我的建议是不要创建多个MPMoviePlayerViewController实例。您可以在具有特定视频快照的单元格上添加一些UIButtonUIImageView。在播放时,您可以创建MPMoviePlayerViewController实例并播放视频