[英]Play AVAudioPlayer From A Sleeping iPhone
I am creating a alarm application. 我正在创建一个警报应用程序。 I am using Audio Session in my main delegate class.
我在主代表班上使用音频会话。
OSStatus result = AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
UInt32 category = kAudioSessionCategory_MediaPlayback;
result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
AudioSessionSetActive(YES);
I am using a separate class for audio playing.But i am not able to play audio when iPhone is sleeping. 我正在使用单独的类进行音频播放。但是我无法在iPhone睡眠时播放音频。
could any one tell me how to use a audio session so that i can play audio file even when iPhone is sleeping. 谁能告诉我如何使用音频会话,以便即使iPhone处于睡眠状态也可以播放音频文件。
Thank You 谢谢
If you're actually using an AVAudioPlayer then try adding this where you handle your initialization: 如果您实际上是在使用AVAudioPlayer,请尝试在处理初始化的位置添加以下内容:
[[AVaudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
The Playback category will allow the sounds to continue if the phone switch is set to vibrate and/or if the phone is locked. 如果电话开关设置为振动和/或电话已锁定,则“播放”类别将允许声音继续播放。
Good luck, 祝好运,
Karl 卡尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.