MPMoviePlayer controlStyle [英] MPMoviePlayer controlStyle

查看:86
本文介绍了MPMoviePlayer controlStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但这不起作用。

推荐答案

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

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


}

这篇关于MPMoviePlayer controlStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆