ios - MPMoviePlayerController 在后台播放音频流

标签 ios mpmovieplayercontroller

当应用程序进入后台时,我在播放音频流时遇到了问题。

我使用代码启动流:

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/

相关文章:

ios - 我们可以在 NSIndexPath 对象中存储什么类型的数据

将 PDF 作为字符串转换为 NSData 后,iOS UIWebView 无法找到 PDF 标题

iphone - MPMoviePlayercontroller 是否可以有自己的洗涤器

iphone - MPMoviePlayerViewController 生成大量错误

ios - 从 Firebase 检索数据时获取错误的时间戳值? (IOS)

objective-c - "Cannot find interface declaration for NSObject"?

mpmovieplayercontroller - MPMoviePlayerController 可以通过编程方式调整音量吗?

iphone - iOS5锁屏后如何继续播放视频音轨?

ios - 为什么 tableViewCell 在返回到 ViewController 时未被选中?

iphone - MPMoviePlayerController - 无法在 < 3GS 上播放我的应用程序中的电影(3GS 没问题)