播放音乐时,应用程序在后台与kAudioSessionCategory

编程入门 行业动态 更新时间:2024-10-26 00:24:55
本文介绍了播放音乐时,应用程序在后台与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类别。更多细节在这里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

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

发布评论

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

>www.elefans.com

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