我正在开发一个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];
但是当播放播放器中有通话时,它会停止。我希望在收到电话后恢复播放器流媒体歌曲。我怎样才能做到这一点?
任何建议都会受到赞赏。
答案 0 :(得分:1)
使用 NSNotificationCenter 为其注册通知。因此,当应用程序到达前台时,您可以恢复播放。 这是处理任何ios应用程序此类事件的正确方法。
有关更多信息,请参阅NSNotificationCenter Class Reference on apple docs
您也可以refer this了解要遵循的具体步骤。
答案 1 :(得分: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.
}
答案 2 :(得分:-1)
根据您的情况尝试这些方法......
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer;
{
[self.audioPlayer pause];
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)audioPlayer;
{
[self.audioPlayer play];
}