当iPhone进入睡眠状态时,AVAudioPlayer停止播放音频

编程入门 行业动态 更新时间:2024-10-23 06:17:37
本文介绍了当iPhone进入睡眠状态时,AVAudioPlayer停止播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

只要我的应用程序正在运行,我就需要一直播放背景声音。我试图将AVAudioPlayer用于此目的。但是,一旦iPhone进入睡眠模式,它就会停止播放声音。

I need to play a background sound all the time as long as my application is running. I tried to use AVAudioPlayer for this purpose. However, it stops playing the sound as soon as the iPhone goes to sleep mode.

你能让我知道如何解决这个问题吗?

Could you let me know how can I fix this problem?

谢谢

推荐答案

您可能需要设置音频会话类别。来自iPhone应用程序编程指南

You may need to set an audio session category. From the "iPhone Application Programming Guide"

类别是为$ b标识音频行为的键$ b申请。通过设置一个类别,你可以将你的音频意图表示为 iPhone OS,例如你的音频是否应该在屏幕锁定时继续。

A category is a key that identifies a set of audio behaviors for your application. By setting a category, you indicate your audio intentions to iPhone OS, such as whether your audio should continue when the screen locks.

每个类别的详细信息都列在音频会话类别

The details about each category are listed at "Audio Session Categories"

更多推荐

当iPhone进入睡眠状态时,AVAudioPlayer停止播放音频

本文发布于:2023-11-27 12:15:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:睡眠   音频   状态   iPhone   AVAudioPlayer

发布评论

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

>www.elefans.com

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