如何在播放MPMoviePlayerController电影之前隐藏控件? [英] How to hide control before MPMoviePlayerController movie is played?

查看:121
本文介绍了如何在播放MPMoviePlayerController电影之前隐藏控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设iOS 3.2或更高版本。使用最初隐藏的控件进行移动的命令的正确顺序是什么。当电影正在播放时,用户可以选择在屏幕上标记并显示控件。

Assume iOS 3.2 or later. What is the proper sequence of command to play a move with the controls initially hidden. When the movie is playing, the user has the option to tag on screen and show controls.

谢谢!

我的(控件未隐藏)代码:

My (control not hidden) code:

- (void)playMovie
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"m4v"]];  
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  

    // Register to receive a notification when the movie has finished playing.  
    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(movieDone:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayer];  

    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(movieState:)  
                                                 name:MPMoviePlayerNowPlayingMovieDidChangeNotification  
                                               object:moviePlayer];  

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(movieReady:) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];


    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
        moviePlayer.controlStyle = MPMovieControlStyleDefault; // MPMovieControlStyleNone MPMovieControlStyleEmbedded MPMovieControlStyleFullscreen MPMovieControlStyleDefault
        moviePlayer.scalingMode = MPMovieScalingModeAspectFill; // MPMovieScalingModeAspectFit MPMovieScalingModeAspectFill
    }   
}

- (void) movieReady:(NSNotification*)notification 
{
    MPMoviePlayerController *moviePlayer = [notification object];  

    if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
        // Remove observer
        [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                        name:MPMoviePlayerLoadStateDidChangeNotification  
                                                      object:nil];

        // When tapping movie, status bar will appear, it shows up
        // in portrait mode by default. Set orientation to landscape
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

        // Add movie player as subview
        [[self view] addSubview:[moviePlayer view]];   

        // Play the movie
        [moviePlayer play];
        [moviePlayer setFullscreen:YES animated:YES];       
    }
}


推荐答案

[更新]正如@ReinYem所提出的,更好的解决方案是依靠MPMoviePlayerLoadStateDidChangeNotification 而不是计时器。

[Update] As proposed by @ReinYem, a much better solution is to rely on a MPMoviePlayerLoadStateDidChangeNotification instead of a timer.

实际上,以下解决方案不应再被视为:

Actually, the following solution should not be considered anymore:

controlStyle 属性设置为 MPMovieControlStyleNone 最初,然后使用 [performSelector:withObject:afterDelay:1] 一秒后将其设置为 MPMovieControlStyleFullscreen
效果很好,直到用户点击视频才会显示控件。

Set controlStyle property to MPMovieControlStyleNone initially, and then set it to MPMovieControlStyleFullscreen one second later using a [performSelector:withObject:afterDelay:1]. It works well, controls do not appear until user taps on video.

这篇关于如何在播放MPMoviePlayerController电影之前隐藏控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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