2011-11-21 60 views
2

在MPMoviePlayerController中,當控件消失時,甚至狀態欄也隨之消失。因爲我想即使控制消失出現在狀態欄,我把下面的代碼如何使狀態欄不會在iOS中的MPMoviePlayerController中消失?

[[UIApplication sharedApplication] setStatusBarHidden:NO]; 但上面的代碼沒有進行任何區別,格蘭狀態欄得到與播放器控件一起消失了。如何解決這個問題呢。

請找到下面的代碼,並讓我知道如何糾正它。

- (void) readyPlayer { 

mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
if ([mp respondsToSelector:@selector(loadState)]) 
    { 
     // Set movie player layout 
     [mp setControlStyle:MPMovieControlStyleFullscreen]; 
     [mp setFullscreen:YES]; 

    // May help to reduce latency 
    [mp prepareToPlay]; 

    // Register that the load state changed (movie is ready) 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; 
     } else { 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification 
                object:nil]; 
     } 
    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
} 

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

    NSLog(@"moviePlayerLoadStateChanged"); 
    // Unless state is unknown, start playback 
    if ([mp loadState] != MPMovieLoadStateUnknown) 
     { 
    // Remove observer 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification 
           object:nil]; 
     [[UIApplication sharedApplication] setStatusBarHidden:NO]; 

     // Rotate the view for landscape playback 
    [[self view] setBounds:CGRectMake(0, 0, 768, 1000)]; 

     // Set frame of movieplayer 
     [[mp view] setFrame:CGRectMake(0, 0, 768, 1000)]; 

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

    // Play the movie 
    [mp play]; 
    } 
} 

- (void) moviePreloadDidFinish:(NSNotification*)notification { 
    // Remove observer 
    NSLog(@"moviePreloadDidFinish"); 
    [[NSNotificationCenter defaultCenter] removeObserver:nil 
                name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification 
                object:nil]; 

    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    // Play the movie 
    [mp play]; 
} 

- (void) moviePlayBackDidFinish:(NSNotification*)notification {  
    NSLog(@"moviePlayBackDidFinish"); 
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    // Remove observer 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification 
          object:nil]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

爲什麼你需要在那裏有狀態欄? – BoltClock

+0

我在我的應用程序中嵌入了播放器,因爲我不是用全屏播放器播放視頻,所以我需要在頂部顯示狀態欄。 – suse

回答

2

這是一個衆所周知的問題MPMovieControlStyleFullscreen。只需使用MPMovieControlStyleEmbedded controlStyle,你就可以走了。

而且,順便說一句,對嵌入式應用來說,這是更合適的controlStyle