After pressing the UIButton, the video appears and starts to play.
Unfortunately, after 3-4 seconds, the video changes Black, the audio is still playing.
Any ideas?
Thank you for all your time.
(Using Xcode 4.2.1)
-(void) playMovieButtonPressed:(UIButton*) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource: ofType:];
NSURL * fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController* player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player.movieSourceType = MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake (20, 400, 300, 200)];
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
}
- (void) moviePlaybackComplete:(NSNotification*) notification {
NSLog(@"videoviewcontroller complete: %@", notification);
MPMoviePlayerController *mymoviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mymoviePlayerController ];
}
-(void) playMovieButtonPressed:(UIButton* ) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource: ofType:];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
// .....
}
I want to use MPMoviePlayerController to play a video in a UIView.
After pressing the UIButton, the video appears and starts to play.
Unfortunately, after 3-4 seconds, the video turns black and the audio is still playing. < br>Any ideas?
Thank you for all your time.
(Using Xcode 4.2.1)
-(void) playMovieButtonPressed:(UIButton*) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource: ofType:];
NSURL * fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController* player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player.movieSourceType = MPMovieSourceTypeFile;
[player.view setFrame:CGRectMake (20, 400, 300, 200)];
[self.view addSubview:player.view];
[ player prepareToPlay];
[player play];
}
- (void) moviePlaybackComplete:(NSNotification*) notification {
NSLog(@"videoviewcontroller complete:% @", notification);
MPMoviePlayerController *mymoviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mymoviePlayerController] ;
)
I talked to an Apple engineer. The solution is that the player must be an instance variable or attribute of the view controller. So it can still be accessed when the view is removed.
-(void) playMovieButtonPressed:(UIButton*) button{
NSString* video = @"testmovie.m4v";
NSString *filepath = [[NSBundle mainBundle] pathForResource: ofType:];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
self.moviePlayerController = [[MPMoviePlaye rController alloc] initWithContentURL:fileURL];
// .....
}