iphone,即使在静音或静音模式下如何播放声音?

iXc*_*der 2 iphone

作为主题......有可能吗?

谢谢

再次,我附上了如下代码,请检查哪一步是错误的.谢谢.

    //@step
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory =   kAudioSessionCategory_MediaPlayback;
OSStatus error = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,                                            sizeof(sessionCategory),&sessionCategory);

if (error) 
    printf("ERROR AudioSessionSetProperty ! %d\n", error);

//@step 
NSString* filePath = @"AlarmClockBell.caf";
[Util restoreResourceFile:filePath];
filePath =[Util getFileFullPathFromSysDoc:filePath];
NSURL *soundFileURL = [NSURL fileURLWithPath:filePath];   
NSError* error ;
AVAudioPlayer * audioPalyer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: &error];
if (nil == audioPalyer) 
{
    AppTrace3(self, @"Faild to play", soundFileURL, error);
    return FALSE;
}
[audioPalyer prepareToPlay];
[audioPalyer setVolume: 5 ];
[audioPalyer setDelegate: self];
 audioPalyer.numberOfLoops = 10;

[audioPalyer play];
Run Code Online (Sandbox Code Playgroud)

谢谢...

Ram*_*min 6

如果您查看音频会话类别下的文档,您将找到许多模式,您可以设置这些模式以告诉系统您的应用计划如何使用音频.默认值是AVAudioSessionCategorySoloAmbient跟踪振铃/静音开关和屏幕锁定.

要让您的应用忽略响铃/静音开关设置,您可以尝试更改类别:

#import <AudioToolbox/AudioToolbox.h>

AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, 
                         sizeof(sessionCategory),&sessionCategory);
Run Code Online (Sandbox Code Playgroud)

如果您想让iPod音频继续在后台播放,您还需要检查kAudioSessionProperty_OverrideCategoryMixWithOthers.