MPMoviePlayerController不从GDataFeedYouTubeVideo播放URL

时间:2012-08-24 13:31:51

标签: xcode mpmovieplayer

我正在使用GDataFeedYouTubeVideo来填充带有图像和标题的tableview。这有效。我想在选择单元格后播放视频。我正在使用feed中的url传递给MPMoviePlayer,看起来它加载因为屏幕变黑,调用了moviePlaybackDidFinish但是没有播放视频并返回显示tableview?来自Feed的示例网址是:

https://www.youtube.com/v/o7QAMH3qRvU?version=3&f=user_uploads&app=youtube_gdata

这可以在浏览器中使用,但不能在MPMoviePlayer中使用吗?请帮我解决这个问题。我宁愿不必写一些hack例程来替换或删除feed返回的URLString。我正在使用ARC&故事板。我第二次选择了一个单元格:

AVPlayerItem类的实例0xce6a7b0已取消分配,而键值观察者仍在其中注册...

是的,我确实尝试了以下建议: iOS 5 an instance of AVPlayerItem was deallocated 这并没有解决它。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    YouTubeVideo *item = [searchList objectAtIndex:indexPath.row];

    if (item != nil) {
        NSURL *url = [NSURL URLWithString:item.URLString];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlaybackDidFinish:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:moviePlayer];
        moviePlayer.controlStyle = MPMovieControlStyleDefault;
        moviePlayer.shouldAutoplay = YES;
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES animated:YES];
    }
}

- (void)moviePlaybackDidFinish:(NSNotification *)notification {
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];

    if ([player respondsToSelector:@selector(setFullscreen:animated:)])
        [player.view removeFromSuperview];
}

1 个答案:

答案 0 :(得分:1)

试过这个,如果我稍微格式化网址就可以了: https://github.com/hellozimi/HCYoutubeParser