当iPhone进入睡眠状态时,AVAudioPlayer停止播放音频 [英] AVAudioPlayer stops playing the audio when iPhone goes to sleep

查看:109
本文介绍了当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停止播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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