我想在按钮点击的同一视图上播放视频。
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视频。
答案 0 :(得分: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 :(得分:1)
首先,您需要致电:
[player play];
其次,释放播放器很可能会立即停止播放。您需要在其他地方挂上该播放器并在电影播放完毕后将其释放。