播放音乐时,应用程序在后台与kAudioSessionCategory_SoloAmbientSound [英] Playing music when application is in background with kAudioSessionCategory_SoloAmbientSound

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

问题描述

我想播放音乐时,我的应用程序在后台运行,所以我给自己定

I want to play music when my application is in the background, so I've set

音频背景模式

在我的应用程序的Info.plist。

in my app's info.plist.

我要的audiosession的类别设置为 kAudioSessionCategory_SoloAmbientSound ,因为我要尊重静音开关,而我不希望与其他应用程序混合。

I want to set the audiosession's category to kAudioSessionCategory_SoloAmbientSound, because I want to respect the mute switch, and I don't want to mix with other applications.

这可能吗?

如果我设置的类别 kAudioSessionCategory_MediaPlayback 然后我的应用程序可以在后台播放音乐,但 kAudioSessionCategory_SoloAmbientSound 当我preSS设备上的主页按钮,它停止播放(当我返回到前台返回播放音乐)。

If I set the category to kAudioSessionCategory_MediaPlayback then my app is able to play music in background, but with kAudioSessionCategory_SoloAmbientSound when I press the home button on the device, it stops playing (and when I return back to the foreground it returns playing music).

所以我想发挥的背景音乐,和尊重静音开关的状态。这可能吗?

So I want to play music in background, and "respect" the mute switch's state. Is that possible?

感谢提前你的答案!

推荐答案

苹果已经告诉我,在后台播放的声音,你需要使用的MediaPlayback类别。更多细节在这里<一个href=\"http://stackoverflow.com/questions/8763942/avaudioplayer-using-ambientsound-session-is-not-playing-when-app-is-in-backgro/8801259#8801259\">AVAudioPlayer,使用AmbientSound会话,是不是在玩的时候应用程序是在后台

Apple have told me that for sound to be played in the background you need to use the MediaPlayback category. More details here AVAudioPlayer, using AmbientSound session, is not playing when app is in background

我有使用的MediaPlayback来解决这个相同的问题,然后试图检测到静音开关的状态复制环境的功能(或你的情况AmbientSolo)。

I am having to solve this same problem by using MediaPlayback and then trying to detect the mute switch state to replicate the functionality of Ambient (or in your case AmbientSolo).

这篇关于播放音乐时,应用程序在后台与kAudioSessionCategory_SoloAmbientSound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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