如何在iphone sdk中播放像你管播放器的视频?

时间:2012-02-17 14:27:31

标签: iphone ios ipad ipod-touch

我是ios开发的新手,我正在开展一个项目,我需要展示一些示例视频。

我想以流媒体格式显示视频(youtube播放器)。

-(void) playVideoOfURL:(NSString*)videoPath
{
    NSString *url = [NSString stringWithFormat:@"%@%@",TipsService,videoPath];

    moviePlayer = [[ MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    if (moviePlayer)
    {

        moviePlayer.view.frame = CGRectMake(0, 0, 320, 460);
        moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 
        moviePlayer.controlStyle = MPMovieControlStyleDefault;
        moviePlayer.movieSourceType = MPMovieSourceTypeFile;
        moviePlayer.useApplicationAudioSession = YES;
        //Register for the playback finished notification.
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];

        //setup device rotation notification observer
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];   
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(didRotate:)
                                                     name:UIDeviceOrientationDidChangeNotification 
                                                   object:nil]; 

        UIViewController *player = [[UIViewController alloc] init];
        player.view = moviePlayer.view;

        [self.navigationController pushViewController:player animated:YES];
        [moviePlayer play];
        [moviePlayer setFullscreen:TRUE];

    }
}

我试过这个,但没用。请帮帮我......

1 个答案:

答案 0 :(得分:1)

试试这个

 [moviePlayer play];
 [moviePlayer setFullscreen:TRUE];
 UIViewController *player = [[UIViewController alloc] init];
 player.view = moviePlayer.view;

 [self.navigationController pushViewController:player animated:YES];