mpmoviez viewcontroller无法在我的应用程序中工作

时间:2011-05-10 04:57:14

标签: iphone

我想通过我的应用程序播放youtube视频链接而不使用webview .. MPMovie视图控制器在我的项目中不起作用..

任何好友都有任何教程或示例代码,然后请将它分享给我..

日Thnx

3 个答案:

答案 0 :(得分:1)

NSURL *movieURL = [NSURL URLWithString:requiredTubeUrl];

if (movieURL)
{
//If required
if ([movieURL scheme])  
{
    MoviePlayerController *myMovie = [[MoviePlayerController alloc] initWithContentURL:movieURL];
    myMovie.frame = urFrame;
    [self.view addSubview:myMovie.view];
    [myMovie play];

}

}

答案 1 :(得分:1)

你可以使用AVPlayer或AVQplayer。你可以找到它的描述形式AVFoundation

答案 2 :(得分:0)

我的代码正在关注加载屏幕,之后没有其他内容

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];


    [player play];                                                                      - (void)moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerViewController *moviePlayer = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayer];

    [moviePlayer.view removeFromSuperview];

    [moviePlayer release];  
}