我在四个不同的视图控制器中有四个视频,它们随机使应用程序崩溃。通常,我单击的第一个(无论它是什么)都会起作用,然后如果我单击按钮播放任何其他视频,应用程序就会崩溃。通常,我首先单击哪个并不重要。该应用程序的行为很奇怪。这是我得到的错误代码:
2013-07-26 10:56:40.590 Capture Controller[6558:907]-[ShoreViewController moviePlayBackDidFinish:]:无法识别的选择器发送到实例 0x2088bb20 2013-07-26 10:56:40.592 Capture Controller[6558:907] * 终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:'-[ShoreViewController moviePlayBackDidFinish:]:无法识别的选择器发送到实例 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:终止调用抛出异常
这是一些代码:
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 的名称不同。任何建议将不胜感激!谢谢!