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

发布于 2024-10-05 12:51:10 字数 461 浏览 0 评论 0原文

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

我正在尝试以静默模式播放声音文件,但结果为零,

我尝试过此代码

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

当我在头文件中导入时,

#import <AudioToolbox/AudioToolbox.h>

创建类似

错误的错误:预期标识符在“\x786f7073”之前

尽快回答.....

提前致谢

关注

愚蠢的iPhone开发者

How to play Sound File In Silent Mode iPhone sdk ?

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

i have tried this code

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

when i import in header file

#import <AudioToolbox/AudioToolbox.h>

create Error like

error: expected identifier before '\x786f7073'

Asnwer As Soon As Possible.....

Thanks In advance

Regard

StupidiPhoneDeveloper

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的温暖 2024-10-12 12:51:10

您必须定义一个不会被静音开关静音的音频会话类别。

查看苹果开发网站上的音频会话页面: http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html%23//apple_ref/ doc/uid/TP40007875-CH4-SW1

也许 AVAudioSessionCategoryPlayAndRecord 就是您需要的。

you have to define an audio session category that is not silenced by the mute switch.

Check out the audio session page on apple dev site : http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html%23//apple_ref/doc/uid/TP40007875-CH4-SW1

Maybe the AVAudioSessionCategoryPlayAndRecord is the one you need.

十二 2024-10-12 12:51:10

感谢好友这么快的回复
我找到了解决方案

通过以下代码,您可以检查您的iPhone配置文件(常规/静音)
这是代码

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'

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

#import <AudioToolbox/AudioToolbox.h>

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

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");
}

And About this error

error: expected identifier before '\x786f7073'

Just write below line in every class header file

#import <AudioToolbox/AudioToolbox.h>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文