当应用程序进入后台时,我在播放音频流时遇到了问题。
我使用代码启动流:
NSURL *mediaURL = [NSURL URLWithString:@"http://url.to.my.stream"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
它工作完美。但是尽管我在应用程序进入后台时在属性列表中设置了标志“应用程序播放音频”,但流停止播放。
如何让我的应用程序在后台播放音频流?
致以最诚挚的问候,非常感谢您的帮助!
最佳答案
我自己没有尝试过,但这看起来很有希望:iOS Multitasking: Background Audio
Once the project has been created go to APP-Info.plist and add UIBackgroundModes as a new row. It should then create the array.
Open the array and to the right of Item 0 set it to audio.
编辑
您的 AVAudioSession 是否设置正确?
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
关于ios - MPMoviePlayerController 在后台播放音频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445604/