2012-02-17 53 views
1

我是新手为ios开发,我正在一个项目,我需要显示一些示例视频。如何在iPhone SDK中播放像你一样的视频播放器?

我想以流媒体格式(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]; 

    } 
} 

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

+0

欢迎StackOverflow上。在提问时,请尽量保持描述性。当你说你尝试过,但它是“没用”,请解释为什么这是没用的,你试图使它工作等等。 – 2012-02-17 14:41:59

回答

1

试试这个

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

[self.navigationController pushViewController:player animated:YES]; 
相关问题