views:

560

answers:

1

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. However 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 appriciated.

-(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;
}
+1  A: 

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;
}
Richard