I'm building an application containing a XML feed with a link to a movie, which I would like to play whenever the user clicks on an image.
For that purpose I'm using the MPMoviePlayerViewController. Testing the app on the simulator has given me the expected results so far, however, when I test the app on an iPhone, the player plays correctly but with no sound.
I've looked on the internet where a few articles told me that the app's performance differs a lot from the performance the simulator gives you. Therefore I made a "leak" test with Instruments, which told me that whenever I started playing a movie, some bytes got dropped or leaked. Could that have something to do with the sudden drop of sound? If so, how would I solve it?
It's my first experience of testing apps on iPhone, so I got pretty shocked seeing how badly the app performed. Here's the code for the movieplayer-part.
#pragma mark Video Controls
-(void)playVideo:(id)sender{
moviePlaying=TRUE;
MPMoviePlayerViewController *playerViewController;
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[data objectForKey:@"[att]url"]]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:[playerViewController moviePlayer]];
MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] init] autorelease];
player = [playerViewController moviePlayer];
[self.view addSubview:playerViewController.view];
player.controlStyle = MPMovieControlStyleDefault;
player.shouldAutoplay = YES;
[player setFullscreen:YES animated:YES];
}
- (void)moviePlayBackDidExitFullscreen:(NSNotification*)notification{
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];
moviePlaying=FALSE;
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
}
#pragma mark VideoControls End
I hope you can light up the problem.
Thanks in advance,
/Brinck10