如何在静音模式下播放声音文件iPhone sdk? [英] How to play Sound File In Silent Mode iPhone sdk?

查看:135
本文介绍了如何在静音模式下播放声音文件iPhone sdk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在静音模式下播放声音文件iPhone sdk?

How to play Sound File In Silent Mode iPhone sdk ?

我试图以静音模式播放声音文件,但结果为零

I m trying to play sound file in silent mode but result is zero

我试过这段代码

SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fullpath],&soundID);
AudioServicesPlaySystemSound (soundID);

#import <AudioToolbox/AudioToolbox.h>

创建错误

错误:预期'\ x在x'之前的标识符

error: expected identifier before '\x786f7073'

Asnwer尽快.....

Asnwer As Soon As Possible.....

在此先感谢

注意

StupidiPhoneDeveloper

StupidiPhoneDeveloper

推荐答案

感谢Buddy快速回复
i已找到解决方案

Thanks Buddy for such a quick reply i have found the solution

通过以下代码,您可以查看您的iPhone配置文件(常规/沉默)
,这里是代码

By the following code you can check your iPhone Profile ( Regular/Silent) and here is the code

CFStringRef state; 
UInt32 propertySize = sizeof(CFStringRef); 
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

if(CFStringGetLength(state) == 0) { 
    //SILENT
NSLog(@"Silent switch is on");

    //create vibrate
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    //this 2 line below use to play audio even in silent/vibrator mode too      

    UInt32 audioCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty( kAudioSessionProperty_AudioCategory, sizeof(UInt32), &audioCategory);
}
else {
    //NOT SILENT
    NSLog(@"Silent switch is off");
}

关于此错误

error: expected identifier before '\x786f7073'

只需在每个类头文件中写下以下行

Just write below line in every class header file

#import <AudioToolbox/AudioToolbox.h>

这篇关于如何在静音模式下播放声音文件iPhone sdk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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