iOS 音频/声音不会在后台模式处于事件状态时在后台播放

标签 ios xcode flutter

我的应用程序(使用 Flutter 制作,但这应该无关紧要)具有类似于计时器的功能,可以定期(10 秒到 3 分钟)发出滴答声。我在我的 Info.plist 中激活了背景模式 Audio、AirPlay 和 Picture in Picture 以及以下内容。

    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>

但在后台运行时音频仍然会停止。

在配置文件模式下运行应用程序时会发生这种情况,当我在 Debug模式下运行时,音频在后台运行时继续。

如何让音频继续在后台运行?

最佳答案

有一个relevant note在 audio_service 0.18.0 自述文件中可以提供帮助:

Note that the audio background mode permits an app to run in the background only for the purpose of playing audio. The OS may kill your process if it sits idly without playing audio, for example, by using a timer to sleep for a few seconds. If your app needs to pause for a few seconds between audio tracks, consider playing a silent audio track to create that effect rather than using an idle timer.

关于iOS 音频/声音不会在后台模式处于事件状态时在后台播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68442752/

相关文章:

ios - 如何正确地将 Last-Modified header 从 HTTP 响应转换为 iOS 上的 NSDate

ios - 拍照时如何改变 UIImagePickerController 中按钮的颜色?

ios - Swift 4 - 使用哪种类型的数组 - 将 JSON 响应解析为数组

xcode - 仅使用日期和月份的 UIDatePicker swift

iphone - 带有 unicode 文本的 UILabel 过多

iphone - 如何从文档目录播放视频(按名称)?

ios - 在 Swift 中以编程方式制作 UIButton

android - 在多个模拟器上运行 flutter 应用程序

flutter - 为什么(通常)在 BLoC 模式上有一个存储库层?

flutter - 使用Flutter向下滚动时如何隐藏带有动画的小部件