15

我整天都在为一个非常烦人的问题而苦苦挣扎,我希望我能在这个板上找到帮助。

我正在使用 MPMoviePlayerController 在 iPad 上播放全屏电影,但我不知道如何删除始终显示的状态栏,尽管我竭尽全力让它下地狱。

这是我用来显示电影的方法的代码:

-(void)launchVideoFromButton:(id)sender{

         NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"movie01" ofType:@"m4v"];
         NSURL *videoPathURL = [NSURL fileURLWithPath:videoPath];
         moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoPathURL];

         [self.view addSubview:moviePlayer.view];

         moviePlayer.shouldAutoplay = YES;
         moviePlayer.movieSourceType = MPMovieSourceTypeFile;


         [moviePlayer setFullscreen:YES animated:YES];
         moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

         NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
         [notificationCenter addObserver:self selector:@selector(moviePlayerEvent:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];

    }



    -(void)moviePlayerEvent:(NSNotification*)aNotification{

         [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
         NSLog(@"%i", [UIApplication sharedApplication].statusBarHidden);

    }

在控制台中,我可以看到当电影出现但状态栏仍然存在时,moviePlayerEvent 被触发: [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO] 似乎无法操作。我一直在尝试使用其他 MPMoviePlayerController 通知,但没有成功。

谁能帮我解决这个问题?

提前致谢。

4

9 回答 9

22

不幸的是,在遇到这个问题后,通过研究和大量实验,我确定在全屏模式下隐藏 iOS 状态栏几乎是不可能的。无论您做什么,当显示全屏播放器控件时,状态栏也会显示(它不会尊重setStatusBarHidden:YES)。嵌入式播放器控件并非如此,但用户可以轻松地在嵌入式和全屏模式之间切换,因此您不能真正使用它来保持控件显示时没有状态栏。

当然,至少当控件淡出时状态栏会消失......

于 2011-04-22T02:50:35.133 回答
9

不要将电影播放器​​的视图添加到您的主视图中;相反,按如下方式显示电影播放器​​(为简洁/清晰起见,省略了一些步骤):

moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

// Register for the playback finished notification.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMovieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerViewController.moviePlayer];


//Present
    [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];

    // Play the movie!
    self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [self.moviePlayerViewController.moviePlayer play];



// When the movie is done, release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{

    //NSLog(@"playback terminated");

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerViewController.moviePlayer];


    [moviePlayerViewController release], moviePlayerViewController = nil;


}
于 2010-09-06T18:19:05.247 回答
2

使用 MPMoviePlayerViewController 对我有用,设置以下

[moviePlayerController.moviePlayer setFullscreen:YES animated:NO];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

在这之前:

[self presentViewController:moviePlayerController animated:NO completion:^{ }];

以及紧随其后的以下内容:

moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;

以防万一,我也这样做了:

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

...


- (void)moviePlayerLoadStateDidChange:(NSNotification *)notification {


    if ([[moviePlayerController moviePlayer] loadState] == MPMovieLoadStateStalled) {

    } else if([[moviePlayerController moviePlayer] loadState] != MPMovieLoadStateUnknown) {

        [moviePlayerController moviePlayer].controlStyle = MPMovieControlStyleNone;

        ...
    }
}

所以,没有状态栏,没有控件……只有纯视频。)

(在 iOS 5.1 设备和 6.0 模拟器上测试)。

于 2012-11-10T01:32:24.600 回答
1

使用 MPMovieControlModeVolumeHidden 对我不起作用,唯一有效的是 MPMovieControlModeVolumeOnly 与全屏视频:

myMoviePlayer.controlStyle = MPMovieControlModeVolumeOnly;
[myMoviePlayer setFullscreen:YES];

而且,我将电影视图作为子视图添加到父视图:

[parentView addSubview:myMoviePlayer.view];

我的应用程序应该没有状态栏,为了向后兼容,我在应用程序委托上使用以下代码:

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
else
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
于 2012-10-02T14:56:14.817 回答
1

状态栏确实隐藏了,但随着播放控制再次出现。

  -(void)viewDidLoad:{
        [super viewDidLoad];
        MPMoviePlayerViewController *moviePlayerViewController =
                [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

        [[NSNotificationCenter defaultCenter] addObserver:self 
                 selector:@selector(playbackStateChange:)
                 name:MPMoviePlayerLoadStateDidChangeNotification
                 object:moviePlayerViewController.moviePlayer];
    }
    -(void)playbackStateChange:(NSNotification*)notification{
        if([[UIApplication sharedApplication]respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
        [[UIApplication sharedApplication] setStatusBarHidden:YES 
                       withAnimation:UIStatusBarAnimationNone];
        else 
            [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
}
于 2010-12-16T13:05:24.210 回答
0

这不是答案,我也有同样的问题。但是有一部分我可以更新..

状态栏仅在控件显示时显示。

单击电影,隐藏控件和状态栏,再次单击,显示控件,状态栏也回来了。

我还在启动电影之前以编程方式隐藏状态栏。

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

这是我添加电影的方式:

[[[UIApplication sharedApplication] keyWindow] addSubview: movieView];

于 2010-12-06T18:13:26.613 回答
0

对于那些遇到此问题的人,我找到了自己的解决方案可能会有所帮助。它仅适用于如果您的应用程序的其余部分不显示状态栏,并且如果您在电影完成并返回您的界面后尝试再次隐藏它,而不是在播放期间。

如果您的 MPMoviePlayerController 作为子视图添加到被推送到导航控制器视图堆栈的 UIView,则可以使用该父视图控制器的 viewWillDisappear 方法来帮助您。

在该方法中,您可以将控件样式更改为无,这将在视图消失之前清除所有电影播放器​​控件,并且如果您已经将其设置为隐藏状态栏,也会将其清除。这对用户来说是完全不明显的,因为视图正在离开屏幕并且他们不再与它交互。

于 2011-12-15T16:04:53.753 回答
0

I don't know if my solution applies to your issue, but it works for my setup, i.e. 4th gen ipod running iOS 5.1.

My applications does not show the status bar at all, and in the info.plist file the corresponding entry "Status bar is initially hidden" is set to YES.

I also directly add the MPMoviePlayerController view to its parent view. Here is the code to setup the movie player:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:frame]; // This is set to (0, 0, 320, 480)
[moviePlayer prepareToPlay];
[moviePlayer setShouldAutoplay:YES]; 
moviePlayer.fullscreen = TRUE;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self.view addSubview:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 

The moviePlayer is a class variable.

When the player finishes playing or when the viewer presses the "Done" button of the moviePlayer controller, the playbackFinished: method is called:

- (void)playBackFinished:(NSNotification *)notif{
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer release];
moviePlayer = nil;
}

In which the control style of the moviePlayer is set to MPMovieControlStyleNone to prevent any controls, but essentially the status bar from showing up when the moviePlayer is removed from its parent view.

于 2013-09-19T11:50:20.487 回答
0

我有同样的问题,但我添加到我的info.plistStatus bar is initially hidden - Boolean - YES并且它有效!
顺便说一句,我使用的是 iOS 5.1,Xcode 4.3.2。

于 2012-05-24T14:54:34.350 回答