我正在使用此代码,以便在没有webview的情况下显示youtube视频
-(IBAction) trailor {
//declaring path to file and stuff...
NSString *urlAddress = self.Trailor;//@"http://www.youtube.com/watch?v=FZXcWK0tZjc&feature=related";
NSLog(@"url %@",urlAddress);
NSURL *url = [NSURL URLWithString:urlAddress];
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
MPMoviePlayerController *player = [playerViewController moviePlayer];
[self.view addSubview:playerViewController.view];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay = YES;
[player setFullscreen:YES animated:YES];
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer.view removeFromSuperview];
//[self.view setHidden:NO];
[moviePlayer release];
}
但是这个代码没有任何响应,当我通过一个按钮运行这个代码时...... 它只显示这个屏幕而没有别的。
我想在没有使用webview的情况下打开我的应用程序的youtube链接我该怎么办
任何示例代码?或者你有教程然后把它分享给我
答案 0 :(得分:0)
那里有类似的(如果不是相同的)问题 youtube donot直接访问视频(MPMoviePlayerViewController期望)。因此它无法直接播放youtube视频(使用initWithContentURL)。
唯一的方法是通过UIWebView在您的应用中播放Youtube视频。看到 How to Play Youtube video in webview in iphone?以便更好地了解如何使用。