2011-04-27 94 views
0

當我嘗試通過iOS 4.3上的MPMoviePlayerViewController播放電影時,現在出現了一個奇怪的問題。 它看起來只是一個白色的屏幕,沒有任何反應。我的代碼在iOS 4.2上運行良好。所以我創建了一個新的OpenGLES項目,並使用我的電影代碼,但它也無法工作。那麼任何人都可以提供一些建議嗎? 在此先感謝。MPMoviePlayerViewController無法在iPhone或iPad上的iOS 4.3上工作

我的代碼如下:

//-------------------------------------TestViewController.h--------------------------------------- 

#import <MediaPlayer/MediaPlayer.h> 

@interface TestViewController : UIViewController 
{ 
    bool _isMovieEnded; 
    MPMoviePlayerViewController* _theMovie; 
} 
- (void)playMovie:(NSString*)filename; 
- (void)movieFinishedCallback:(NSNotification*)aNotification; 
- (bool)isMovieEnd; 

//-------------------------------------TestViewController.m--------------------------------------- 

- (void)playMovie:(NSString*)filename 
{ 
    NSURL* theURL = [NSURL fileURLWithPath:filename]; 
    _theMovie = [[MPMoviePlayerViewController alloc] init];// initWithContentURL:theURL]; 
    [_theMovie.moviePlayer setContentURL:theURL]; 
    _theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 
    [_theMovie.moviePlayer setControlStyle:MPMovieControlStyleNone]; 
    [_theMovie.moviePlayer setFullscreen:YES]; 

    // register notification 
    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(movieFinishedCallback:) 
             name:MPMoviePlayerPlaybackDidFinishNotification 
             object:_theMovie]; 

    [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 
    [_theMovie.moviePlayer play]; 
    [self.view addSubview:_theMovie.view]; 
} 

- (void)movieFinishedCallback:(NSNotification*)aNotification 
{ 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:_theMovie]; 

    // release movie 
    [_theMovie.view removeFromSuperview]; 
    [_theMovie release]; 

    _isMovieEnded = true; 
    [self startAnimation]; 

    [[UIApplication sharedApplication] endIgnoringInteractionEvents]; 
} 

- (bool)isMovieEnd 
{ 
    return _isMovieEnded; 
} 

//-------------------------------------TestAppDelegate.m--------------------------------------- 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{ 
    [self.window addSubview:self.viewController.view]; 

    NSString* movieFile = [[NSBundle mainBundle] pathForResource:@"logo" ofType:@"mp4"]; 
    [viewController playMovie:movieFile]; 
    [viewController stopAnimation]; 

    return YES; 
} 

回答

0
// Determines if the movie is presented in the entire screen (obscuring all other application content). Default is NO. 
// Setting this property to YES before the movie player's view is visible will have no effect. 
@property(nonatomic, getter=isFullscreen) BOOL fullscreen; 
- (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated; 

從MPMoviePlayerController.h

所以在這裏你是代碼:

- (void)playVideoFromUrl:(NSString*)url { 
    MPMoviePlayerViewController *moviePlayer = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]] autorelease]; 

    [((UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0]).rootViewController presentMoviePlayerViewControllerAnimated:moviePlayer]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) 
               name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    [moviePlayer.moviePlayer setFullscreen:YES animated:YES]; 
    [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 
} 

- (void)moviePlaybackComplete:(NSNotification *)notification { 
    MPMoviePlayerViewController *moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    [((UIWindow*)[[UIApplication sharedApplication].windows objectAtIndex:0]).rootViewController dismissMoviePlayerViewControllerAnimated]; 
} 
相關問題