Question

I have four videos in four different view controllers and they randomly crash the app. Generally the first one I click (regardless of which it is) will work and then if I click the button to play any other video the app crashes. It does not matter which one I click first, generally. The app behaves strangely. Here is the error code I get:

2013-07-26 10:56:40.590 Capture Controller[6558:907] -[ShoreViewController moviePlayBackDidFinish:]: unrecognized selector sent to instance 0x2088bb20 2013-07-26 10:56:40.592 Capture Controller[6558:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ShoreViewController moviePlayBackDidFinish:]: unrecognized selector sent to instance 0x2088bb20' * First throw call stack: (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 called throwing an exception

Here is some code:

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

The rest of the view controllers are basically the same, just with of course different names for the IBActions and moviePlayers. Any advice would be much appreciated! Thanks!

Was it helpful?

Solution

I don't see a method named:

- (void) moviePlayBackDidFinish:(NSNotification*)notification

in any of the code snippets you've cut & pasted (although it's not obvious if either view controller is actually your "ShoreViewController" object, either)

If it doesn't exist in your code, that would explain the "unrecognized selector sent to instance" crash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top