im trying to add a video to a button click (native video) i had the code down perfect and it compiles and runs ok but when i click on that button thats meant to natively play the video... it gives me a "Thread 1: Signal SIGBART" ??? how can i fix this please?
i have followed everything as i should, imported the video into supporting files and made sure to give it the same name in .m as its file name.
Tried adding a breakpoint exception but wont work
here is the code in .h
@interface ViewController5 : UIViewController {
}
-(IBAction)play;
@end
here is the code in .m
@implementation ViewController5
-(IBAction)play {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"test video" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}
@end
And here is the "green" highlight signal i get
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
If you're using ARC, you should keep a reference to MPMoviePlayerViewController
instance so it's not deallocated when play
method returns, and don't set it to nil
.
// ViewController5.h
@interface ViewController5 : UIViewController {
MPMoviePlayerViewController *playercontroller;
}
- (IBAction)play;
@end
// ViewController5.m
@implementation ViewController5
- (IBAction)play {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test video" ofType:@"mp4"]];
playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
}
@end