2013-12-19 55 views
1

我有一個新聞提要屏幕的應用程序,就像facebook應用程序中的應用程序一樣。爲此,我製作了一個自定義單元格,其中有一個contentView,它是一個UIView。這個contentView被初始化爲顯示文本,圖像或視頻。這是在自定義單元的類中完成的。對於視頻,我想MPMoviePlayerViewController添加爲一個子視圖到該單元的內容查看:自定義單元格中的MPMoviePlayerViewController

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 

我該如何解決這個問題?

回答

2

正如您將player.moviePlayer.view添加到內容視圖。

所以雖然檢索你會得到參考player.moviePlayer.view而不是MPMoviePlayerViewController

我的建議是不要創建多個MPMoviePlayerViewController實例。您可以在特定視頻的快照上添加一些UIButtonUIImageView。而只玩你可以創建MPMoviePlayerViewController實例和播放你的視頻

+0

我知道這就是發生了什麼,我只是想知道如何解決它:) – damjandd

+1

工作是做Bhumeshwer katre說。不要將電影加載到每個單元格中。只需加載代表性的UIImage或播放圖標即可。然後當你的用戶點擊它時,你可以創建一個新的MPMoviePlayerController來播放你的電影。如果你想在每個表格行單元中播放一個電影流(我不認爲這是一個好主意),那麼你最好看看AVPlayer。 – Justyn

+0

很好的答案謝謝!我正在做類似的事情。我在每個單元格中創建了一個'MPMoviePlayerViewController'實例,它絕對不會像我想的那樣流暢。 – SuperKevin