0

我正在开发一个 iphone 应用程序,我在其中使用 MPMoviePlayerViewController 播放流式音频。使用以下代码,它工作正常。

moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 83, 1024, 400)];
   moviePlayerController.moviePlayer.controlStyle = MPMovieControlModeVolumeOnly;
[moviePlayerController.moviePlayer prepareToPlay];
    moviePlayerController.moviePlayer.shouldAutoplay=YES;
   [moviePlayerController.moviePlayer play];

但是当播放播放器期间有呼叫时,它会停止。我想在接到电话后恢复播放器流式播放歌曲。我怎样才能做到这一点?

Plaese 任何建议将不胜感激。

4

3 回答 3

1

使用NSNotificationCenter为其注册一个通知。因此,当应用程序进入前台时,您可以恢复播放。这是为任何 ios 应用程序处理此类事件的正确方法。

有关更多信息,请参阅苹果文档上的 NSNotificationCenter 类参考

您也可以参考此内容以了解要遵循的确切步骤。

于 2013-05-02T08:35:17.523 回答
0

您可以使用在应用程序委托类中实现的给定方法

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
于 2013-05-02T10:15:26.140 回答
-1

根据您的情况尝试这些方法...

-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer;
{
    [self.audioPlayer pause];
}

-(void)audioPlayerEndInterruption:(AVAudioPlayer *)audioPlayer;
{
    [self.audioPlayer play];
}

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html以获得进一步的帮助..

于 2013-05-02T10:54:11.527 回答