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

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

问题描述

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

  • 设备被锁定
  • 用户使用另一个应用程序

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

对此有什么提示吗?

解决方案

播放背景音频

<块引用>

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

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

确保在屏幕锁定时音频继续

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

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:

  • the device is locked
  • the user uses another application

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

Any tips for that ?

解决方案

Playing Background Audio

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 reference "Playing and Recording Background Audio"

Ensuring That Audio Continues When the Screen Locks

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天全站免登陆