Youtube视频有时在ios中不起作用

时间:2014-04-04 09:24:45

标签: ios objective-c youtube xcode5

我需要澄清在ios中导入的youtube视频网址。我的场景是,我创建了一个tableview,当我点击单元格时,它将导航到我的Detailviewcontroller。在detailviewcontroller页面中我有一个UIButton,当我点击该按钮时,它将播放一个视频。此视频网址包含youtube视频网址。它在3天之前工作正常。现在它不起作用。我不知道我的代码中有什么错误。

我的代码是: DetailViewController.m

-(IBAction)YouTube:(id)sender
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    PlayViewController *PVC = [storyboard instantiateViewControllerWithIdentifier:@"PlayViewController"];
    PVC.videourl=strVideoURL;
    [self.navigationController pushViewController:PVC animated:YES];
}

PlayViewController.m

-(void)viewDidLoad
{
    NSArray *arr=[YoutubeParser parseHTML:videourl];
    NSString *myArrayString = [arr objectAtIndex:0];
    videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:myArrayString];
    [self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [defaultCenter addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
    [defaultCenter addObserver:self selector:@selector(moviePlayerLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

}

1 个答案:

答案 0 :(得分:1)

我自己找到答案。这里我用旧版XCDYouTubeVideoPlayerViewController播放视频。现在我从这里下载了新文件https://github.com/0xced/XCDYouTubeVideoPlayerViewController。现在问题已经解决了。