iphone mpmovieplayercontroller mp3显示黑色背景

时间:2009-09-30 13:36:21

标签: iphone background mpmovieplayercontroller

我有一个按钮,触发mpmovieplayercontroller播放一些流音频。当控制器正在播放时,一切都按预期工作,我看到灰色的快速时间背景。

然而,当我停止播放器并再次按下按钮时,我仍然听到音频,但背景现在是黑色的。而且,如果我在播放mp3之前切换到视频流,则会再次出现quicktime背景。

有没有人知道如何阻止quicktime背景消失。

非常感谢任何帮助。

-(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 个答案:

答案 0 :(得分:1)

找到答案基本上与玩家没有正确停止有关。您需要将DidFinish函数更改为以下

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