MPMoviePlayerController在后台播放音频流 [英] MPMoviePlayerController playing audio stream in the background

查看:59
本文介绍了MPMoviePlayerController在后台播放音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序进入后台时,我在播放音频流时遇到麻烦.

I am running into trouble with playing an audio stream when the application enters background.

我使用代码启动流:

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];

效果完美.但尽管如此,当应用程序进入后台时,我会在属性列表中设置应用程序播放音频"标记,流将停止播放.

It works perfect. But allthough I set the flag 'App plays audio' in the property list when the app enters background the stream stops playing.

如何使我的应用程序在后台播放音频流?

How do I make my application play the audio stream in the background?

最诚挚的问候,非常感谢您的帮助!

Best regards and thanks a lot for help!

推荐答案

我自己没有尝试过,但这看起来很有希望:

I didn't tried it myself but this looks promising: iOS Multitasking: Background Audio

创建项目后,转到APP-Info.plist并添加 UIBackgroundModes作为新行.然后应该创建数组.

Once the project has been created go to APP-Info.plist and add UIBackgroundModes as a new row. It should then create the array.

打开数组,然后在Item 0的右侧将其设置为音频.

Open the array and to the right of Item 0 set it to audio.

编辑

您的AVAudioSession是否设置正确?

Is your AVAudioSession set up properly?

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];

这篇关于MPMoviePlayerController在后台播放音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆