如何在 iOS 设备被锁定或在另一个应用程序上处理背景音频播放? [英] How to handle background audio playing while iOS device is locked or on another application?

查看:20
本文介绍了如何在 iOS 设备被锁定或在另一个应用程序上处理背景音频播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 OpenFrameworks 为 iOS 设计一个生成音乐系统,我需要提供一种模式,让用户可以在以下情况下聆听应用程序生成的音乐:

Designing a generative music system for iOS, using OpenFrameworks, I'd need to provide a mode in which the user could listen the music produced by the application when:

  • 设备已锁定
  • 用户使用其他应用程序

一些应用程序,如 BLOOM 或闹钟,就是这样工作的,并向用户建议启用/禁用此功能的开关.

Some applications like BLOOM, or alarm clock, works like that and propose to users a switch to enable/disable this feature.

有什么建议吗?

推荐答案

播放背景音频

连续播放或录制音频的应用程序(即使应用程序在在后台运行)可以注册以在背景.您从背景模式部分启用音频支持Xcode 项目中的 Capabilities 选项卡.(您也可以启用通过在音频中包含 UIBackgroundModes 键来支持此功能应用程序的 Info.plist 文件中的值.)播放音频内容的应用程序背景必须播放有声内容而不是静音.

An app that plays or records audio continuously (even while the app is running in the background) can register to perform those tasks in the background. You enable audio support from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the audio value in your app’s Info.plist file.) Apps that play audio content in the background must play audible content and not silence.

Apple 参考播放和录制背景音频"

确保屏幕锁定时音频继续播放

为了启用/禁用此功能,我发现 激活和停用你的音频会话,我自己没试过,但看起来你需要的.

For enabling/disabling this feature I found Activating and Deactivating Your Audio Session, I haven't tried it myself, but it looks like what you need.

这篇关于如何在 iOS 设备被锁定或在另一个应用程序上处理背景音频播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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