应用程序崩溃来自多个视频

时间:2013-07-26 19:33:57

标签: ios video movie

我在四个不同的视图控制器中有四个视频,它们会随机崩溃应用程序。通常我点击的第一个(无论它是什么)将工作,然后如果我点击按钮播放任何其他视频应用程序崩溃。一般来说,首先点击哪一个并不重要。该应用程序表现得很奇怪。这是我得到的错误代码:

  

2013-07-26 10:56:40.590捕获控制器[6558:907]    - [ShoreViewController moviePlayBackDidFinish:]:无法识别的选择器发送到实例0x2088bb20 2013-07-26 10:56:40.592 Capture   控制器[6558:907] *由于未捕获的异常而终止应用程序   'NSInvalidArgumentException',原因:' - [ShoreViewController   moviePlayBackDidFinish:]:发送到实例的无法识别的选择器   0x2088bb20'   * 第一次抛出调用堆栈:(0x339c43e7 0x3b84e963 0x339c7f31 0x339c664d 0x3391e208 0x33915349 0x3422cb7f 0x3484fec7 0x3484d251   0x33915349 0x3422cb7f 0x34866557 0x3486916f 0x34253b85 0x342537dd   0x3422dcbb 0x348ef73f 0x34253b85 0x342537dd 0x3422dcbb 0x348f208d   0x348f4149 0x348f1f2d 0x348f3d59 0x348f05d9 0x34862bcb 0x3484ddc7   0x33915349 0x3422cb7f 0x3484fc5b 0x3484f6a7 0x3484c055 0x49e61   0x358be087 0x358be03b 0x358be015 0x358bd8cb 0x358bddb9 0x357e65f9   0x357d38e1 0x357d31ef 0x374c75f7 0x374c7227 0x339993e7 0x3399938b   0x3399820f 0x3390b23d 0x3390b0c9 0x374c633b 0x358272b9 0x26a2d   0x3bc7bb20)libc ++ abi.dylib:terminate调用抛出异常

以下是一些代码:

EBViewController.h:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "ReaderViewController.h"
@interface EBViewController : UIViewController <ReaderViewControllerDelegate>
@property (strong, nonatomic) MPMoviePlayerController *movieEBPlayer;
- (IBAction)playEBFilm:(id)sender;
- (IBAction)readEBDocument:(id)sender;
@end

EBViewController.m

#import "EBViewController.h"

@interface EBViewController ()

@end

@implementation EBViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *EBFilmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [EBFilmButton addTarget:self action:@selector(playEBFilm) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:EBFilmButton];
    UIButton *readEBButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [readEBButton addTarget:self action:@selector(readEBDocument) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:readEBButton];
}
-(void)readEBDocument:(id)sender {
    NSString *file = [[NSBundle mainBundle] pathForResource:@"Rig" ofType:@"pdf"];
    ReaderDocument *document = [ReaderDocument withDocumentFilePath:file password:nil];
    if (document != nil)
    {
        ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
        readerViewController.delegate = self;
        readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentModalViewController:readerViewController animated:YES];
    }
}



-(void)playEBFilm:(id)sender
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"118409050" ofType:@"mp4"]; NSURL *url = [NSURL fileURLWithPath:path];   MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url]; [player play]; //- See more at: http://getsetgames.com/2009/12/20/iphonedev-advent-tip-20-how-to-play-a-video-with-mpmovieplayercontroller/#sthash.dznrF0UO.J8xsiXHT.dpuf

    _movieEBPlayer =  [[MPMoviePlayerController alloc]
                           initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:_movieEBPlayer];

    _movieEBPlayer.controlStyle = MPMovieControlStyleDefault;
    _movieEBPlayer.shouldAutoplay = YES;
    [self.view addSubview:_movieEBPlayer.view];
    [_movieEBPlayer setFullscreen:YES animated:YES];
}
- (void)dismissReaderViewController:(ReaderViewController *)viewController {
    [self dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

PebbleViewController.h:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "ReaderViewController.h"
@interface PebbleViewController : UIViewController <ReaderViewControllerDelegate>
@property (strong, nonatomic) MPMoviePlayerController *moviePebblePlayer;
- (IBAction)playPebbleFilm:(id)sender;
- (IBAction)readPebbleDocument:(id)sender;
@end

PebbleViewController.m:

#import "PebbleViewController.h"

@interface PebbleViewController ()

@end

@implementation PebbleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *pebbleFilmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [pebbleFilmButton addTarget:self action:@selector(playPebbleFilm) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pebbleFilmButton];
    UIButton *readPebbleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [readPebbleButton addTarget:self action:@selector(readPebbleDocument) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:readPebbleButton];
}
-(void)readPebbleDocument:(id)sender {
    NSString *file = [[NSBundle mainBundle] pathForResource:@"Rig" ofType:@"pdf"];
    ReaderDocument *document = [ReaderDocument withDocumentFilePath:file password:nil];
    if (document != nil)
    {
        ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
        readerViewController.delegate = self;
        readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentModalViewController:readerViewController animated:YES];
    }
}



-(void)playPebbleFilm:(id)sender
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Pebble2" ofType:@"mov"]; NSURL *url = [NSURL fileURLWithPath:path];   MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url]; [player play]; //- See more at: http://getsetgames.com/2009/12/20/iphonedev-advent-tip-20-how-to-play-a-video-with-mpmovieplayercontroller/#sthash.dznrF0UO.J8xsiXHT.dpuf

    _moviePebblePlayer =  [[MPMoviePlayerController alloc]
                     initWithContentURL:url];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:_moviePebblePlayer];

    _moviePebblePlayer.controlStyle = MPMovieControlStyleDefault;
    _moviePebblePlayer.shouldAutoplay = YES;
    [self.view addSubview:_moviePebblePlayer.view];
    [_moviePebblePlayer setFullscreen:YES animated:YES];
}
- (void)dismissReaderViewController:(ReaderViewController *)viewController {
    [self dismissModalViewControllerAnimated:YES];
}

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

@end

其余的视图控制器基本相同,当然只有IBActions和moviePlayers的不同名称。 任何建议将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:2)

我没有看到名为的方法:

- (void) moviePlayBackDidFinish:(NSNotification*)notification

在您剪切的任何代码段中&amp;粘贴(虽然任何一个视图控制器实际上都是你的“ShoreViewController”对象并不明显)

如果您的代码中不存在,则会解释“发送到实例的无法识别的选择器”崩溃。