R – iphone mpmovieplayercontroller mp3 showing black background

backgroundiphonempmovieplayercontroller

I have a button that triggers a mpmovieplayercontroller to play out some streaming audio. When the controller is playing everything works as expected and I see the grey quicktime background.

However, when I stop the player and press the button again, I still hear the audio, but the background is now black. And, if I switch to a video stream before playing the mp3 the quicktime background reappears.

Does any one know how to stop the quicktime background disappearing.

Any help is greatly appreciated.

-(IBAction) playmp3 {
NSString *medialink = @"http://someWebAddress.mp3";
self.player = [[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:medialink]] autorelease];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidFinish:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.player];
[self.player play];
}

- (void)moviePlayerDidFinish:(NSNotification *)obj {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.player];
self.player = nil;
}

Best Answer

Found the answer basically it has to do with the player not stopping correctly. You need to alter the DidFinish function to the following

- (void)moviePlayerDidFinish:(NSNotification *)obj {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"MPMoviePlayerPlaybackDidFinishNotification" object:self.player];
self.player.initialPlaybackTime = -1.0;
[self.player stop];
self.player = nil;
}
Related Topic