MPMoviePlayerController在后台播放音频流

编程入门 行业动态 更新时间:2024-10-25 20:31:27
本文介绍了MPMoviePlayerController在后台播放音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

我使用代码启动流:

NSURL *mediaURL = [NSURL URLWithString:@"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!

推荐答案

我自己没有尝试过,但这看起来很有希望: iOS多任务处理:背景音频

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在后台播放音频流

本文发布于:2023-07-11 09:06:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   音频   MPMoviePlayerController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!