2011-06-17 76 views
2

我想在點擊按鈕的相同視圖上播放視頻。我們可以添加mpmovieplayerviewcontroller作爲子視圖嗎?

NSURL *movieUrl = @"Some Url"; 
      CGRect frame; 
      frame =CGRectMake(10,10,100,100); 
      MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl]; 
      [self.view addSubview:player.view]; 
      player.view.frame = frame; 
      [player release]; 

當我運行這個,它顯示一個黑色的背景幀,但不播放視頻。我沒有使用YouTube視頻。

回答

8
NSURL* videoURL = [NSURL URLWithString:url]; 
MPMoviePlayerController* mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
[mPlayer prepareToPlay]; 
[mPlayer play]; 

//For viewing partially..... 
[mPlayer.view setFrame:CGRectMake(50, 200, (self.view.frame.size.width)-100 , 400)]; 
mPlayer.view.backgroundColor = [UIColor grayColor]; 
[self.view addSubview:mPlayer.view]; 
1

首先,你需要調用:

[player play]; 

二,立即釋放玩家將最有可能停止播放。您需要將其掛在其他地方,並在電影完成播放時釋放它。

+0

感謝的reply.When我寫[Player中]應用crashes.give我solution.Please – 2011-06-18 05:37:54

+0

我發現這裏的答案http://stackoverflow.com/questions/2218158/using-mpmovieplayerviewcontroller-in -sdk-3-2換的ipad – 2011-06-18 06:17:18

相關問題