2

我想使用以下代码隐藏 MPMoviePlayer 的控件:

-(IBAction)video:(id)sender {

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Intro" ofType:@"mov"];
NSURL *movie = [NSURL fileURLWithPath:moviePath];

MPMoviePlayerController *control = [[MPMoviePlayerController alloc]initWithContentURL:movie];
//[self.view addSubview: control.view];

control.scalingMode = MPMovieScalingModeFill;
control.controlStyle = MPMovieControlStyleNone;
control.shouldAutoplay = YES;



[control play];

MPMoviePlayerViewController *movieplayer = [[MPMoviePlayerViewController alloc]initWithContentURL:movie];
[self presentMoviePlayerViewControllerAnimated:movieplayer];  }

但这不起作用。

4

4 回答 4

1

你在重复代码。MPMoviePlayerViewController 有 MPMoviePlayerController。所以用它作为movieplayervc.moviePlayer.controlStyle = MPMovieControlStyleNone;

于 2012-10-30T13:10:46.707 回答
0

你试过这个吗 [videoPlayerobj setControlStyle:MPMovieControlStyleNone];

于 2012-10-29T11:54:52.123 回答
0

我的播放器设置在 viewDidLoad 中,这一行隐藏了 MPMoviePlayerController。我已将我的 MPMoviePlayer 控制器初始化为 *stream。

stream.view.hidden = YES;

希望这可以帮助!

于 2013-12-05T18:15:13.180 回答
0

您可以使用此代码播放视频和停止视频并从自定义视图中删除。并且MPMoviePlayerController是电影播放器​​。希望这对你有用。谢谢

 -(void)playMovie:(id)sender {

        UIButton *buttonThatWasPressed = (UIButton *)sender;
        buttonThatWasPressed.enabled = NO;
        NSString * str=[[NSBundle mainBundle]pathForResource:@"yo2" ofType:@"mov"];
        NSURL * url=[NSURL fileURLWithPath:str];
        MPMoviePlayerController * movieController=[[MPMoviePlayerController alloc]initWithContentURL:url];
        movieController.controlStyle=MPMovieControlStyleFullscreen;
        [movieController.view setFrame:self.view.bounds];
        [self.view addSubview:movieController.view];
        [movieController prepareToPlay];
        [movieController play];
        _moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:url];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                   selector:@selector(moviePlayBackDidFinish:)
                                   name:MPMoviePlayerPlaybackDidFinishNotification
                                   object:_moviePlayer];

       [[NSNotificationCenter defaultCenter] addObserver:self 
                                   selector:@selector(moviePlayBackDonePressed:)
                                   name:MPMoviePlayerDidExitFullscreenNotification 
                                   object:_moviePlayer];

       _moviePlayer.controlStyle = MPMovieControlStyleDefault;
       _moviePlayer.shouldAutoplay = YES;
       [self.view addSubview:_moviePlayer.view];
       [_moviePlayer setFullscreen:YES animated:YES]; }

当您的视频或电影从用户停止或视频播放完成时调用此方法。

 -(void) moviePlayBackDonePressed:(NSNotification*)notification {
         [_moviePlayer stop];
         [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:_moviePlayer]; 
         if ([_moviePlayer respondsToSelector:@selector(setFullscreen:animated:)])
         {
              [_moviePlayer.view removeFromSuperview];
         }
         _moviePlayer=nil;   
        [self dismissViewControllerAnimated:YES
                          completion:^{
                              [self   performSegueWithIdentifier:@"show" sender:self];
        }]; 
 }

 - (void) moviePlayBackDidFinish:(NSNotification*)notification {    // Remove observer
     [[NSNotificationCenter defaultCenter] removeObserver:self
                                                      name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];

   [self dismissViewControllerAnimated:YES
                          completion:^{
                              [self performSegueWithIdentifier:@"show" sender:self];
                          }];


}
于 2016-07-30T07:10:52.950 回答