【问题标题】:Audio and vibrate working in simulator not on ios device音频和振动在模拟器中工作而不是在 ios 设备上
【发布时间】:2011-10-08 20:59:41
【问题描述】:

首先,我对目标 C 很陌生。我想在特定条件下播放声音和振动。我的 iPhone 4 没有静音,我检查了区分大小写并使用了 AVAudioPlay 和 SystemSound 来尝试播放文件,但即使是振动也不起作用。 AudioToobox 和 AVfoundation 在 .h 中导入。在 iOS 模拟器上使用这两种方法播放音频。

这是使用 SystemSound 的代码:

if (al == 1){
CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Alarm", CFSTR ("wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
        AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);}

还有 AVAudioPlayer:

if (al == 1) {NSString *path = [[NSBundle mainBundle] pathForResource:@"alarmtwo" ofType:@"wav"];
        AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];        
        theAudio.numberOfLoops = 0;
        theAudio.volume = 1.5;
        [theAudio prepareToPlay];
        [theAudio play];}

顺便说一句,变量 al 在播放后设置为 0。我的编码是否错误,无法在设备本身上发出声音和振动?是否需要播放特定类型的 .wav 文件?任何帮助将不胜感激。

【问题讨论】:

    标签: objective-c ios xcode audio vibration


    【解决方案1】:

    我遇到了同样的问题。实际上有第二个音量设置专门用于警报,至少在我的情况下被设置为静音,即使我的常规音量已经提高。查看设备上“设置”应用中的声音菜单,然后将其打开。

    如果声音实际播放很重要,您可能不希望将警报用于实际发布的应用程序,因为它需要用户确保此单独的音频设置已启动。

    【讨论】:

    • 那么有没有办法在关闭设置的同时打开播放振动?除非我们提示用户打开振动...
    • 尴尬,但那是我的问题!感谢您的提醒。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多