单击全屏按钮时MPMoviePLayerController崩溃

时间:2014-01-01 18:26:47

标签: mpmovieplayercontroller

我在侧边栏中使用SWRealViewController。 我的moviePlayer工作正常,全屏,但当我点击全屏moviePlayer崩溃,我得到一个错误:

  

2014-01-01 19:23:00.860 Chingfong [56193:70b]警告:尝试   从视图控制器中解雇   正在进行陈述或解雇!

这是我在movieVC.h中的代码

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface movieVC : UIViewController
{
    NSString *link;
}

@property(nonatomic,retain) NSString *link;
@property(nonatomic, strong)UIActivityIndicatorView *activityIndicator;
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

@end

这里是movieVC.m

#import "movieVC.h"
#import "SWRevealViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface movieVC ()

@end

@implementation movieVC
@synthesize link;
@synthesize activityIndicator;

- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteredFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    NSString *urlAddress = link;

    //Create a URL object.
    NSURL *url1 = [NSURL URLWithString:urlAddress];

    self.moviePlayer =  [[MPMoviePlayerController alloc]
                         initWithContentURL:url1];
    self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    self.moviePlayer.view.frame = CGRectMake(0,0,320,180);
    [self.view addSubview:_moviePlayer.view];
    self.moviePlayer.shouldAutoplay = NO;
    [self.moviePlayer setFullscreen:YES animated:YES];

}


- (void)willEnterFullscreen:(NSNotification*)notification {
    NSLog(@"willEnterFullscreen");

}

- (void)enteredFullscreen:(NSNotification*)notification {
    NSLog(@"enteredFullscreen");

}

- (void)willExitFullscreen:(NSNotification*)notification {
    NSLog(@"willExitFullscreen");

}

- (void)exitedFullscreen:(NSNotification*)notification {
    NSLog(@"exitedFullscreen");
    [self.moviePlayer stop];
    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

- (void)playbackFinished:(NSNotification*)notification {
    NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
    switch ([reason intValue]) {
        case MPMovieFinishReasonPlaybackEnded:
            NSLog(@"playbackFinished. Reason: Playback Ended");
            break;
        case MPMovieFinishReasonPlaybackError:
            NSLog(@"playbackFinished. Reason: Playback Error");
            break;
        case MPMovieFinishReasonUserExited:
            NSLog(@"playbackFinished. Reason: User Exited");
            break;
        default:
            break;
    }
    [self.moviePlayer setFullscreen:NO animated:YES];
}

- (void)showMovie {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteredFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    NSString *urlAddress = link;

    //Create a URL object.
    NSURL *url1 = [NSURL URLWithString:urlAddress];

    self.moviePlayer =  [[MPMoviePlayerController alloc]
                     initWithContentURL:url1];
    self.moviePlayer.view.frame = CGRectMake(0,0,320,180);
    [self.view addSubview:_moviePlayer.view];
    [self.moviePlayer setFullscreen:YES animated:YES];
    [self.moviePlayer play];
}

-(void)viewWillDisappear:(BOOL)animated {
    [self.moviePlayer stop];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

0 个答案:

没有答案