MPMoviePlayer controlStyle

最后都变了- 提交于 2020-01-11 11:12:05

问题


I want to hide the controls from the MPMoviePlayer with this code:

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

But that does not work.


回答1:


You are repeating code. MPMoviePlayerViewController has MPMoviePlayerController. So use it as movieplayervc.moviePlayer.controlStyle = MPMovieControlStyleNone;




回答2:


have you tried this [videoPlayerobj setControlStyle:MPMovieControlStyleNone];




回答3:


My player is set up in the viewDidLoad and this line hides the MPMoviePlayerController. I have intialised my MPMoviePlayer controller as *stream.

stream.view.hidden = YES;

Hope this helps!




回答4:


You can play video and stop video and remove from your custom view with this code. and MPMoviePlayerController is movie player. Hope this is useful for you.thank you

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

This method is called when your video or movie is stop from user or video playback has finish.

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


}


来源:https://stackoverflow.com/questions/13121032/mpmovieplayer-controlstyle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!