2011-04-27 59 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]; 
} 
相关问题