MPMoviePlayerViewController не может работать на iOS 4.3 на iPhone или iPad

#iphone #ipad #ios4

#iPhone #iPad #ios4

Вопрос:

Теперь у меня странная проблема, когда я пытаюсь воспроизвести фильм через MPMoviePlayerViewController на iOS 4.3. Появляется просто белый экран, и ничего не происходит. Мой код хорошо работает на iOS 4.2. Поэтому я создал новый проект OpenGLES и просто использую свой код фильма, но он тоже не может работать. Итак, кто-нибудь может дать несколько советов? Заранее спасибо.

Мой код приведен ниже:

 //-------------------------------------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;
}
  

Ответ №1:

 // 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];
}