简体   繁体   English

音频和振动在模拟器中工作,而不是在ios设备上

[英]Audio and vibrate working in simulator not on ios device

First off, I'm fairly new with objective C. I want to play a sound and vibrate under a certain condition. 首先,我对目标C很新。我想在一定条件下发出声音并振动。 My iPhone 4 is not on mute, I've checked case sensitivity and used both AVAudioPlay and SystemSound to try and play the file but even the vibrate will not work. 我的iPhone 4没有静音,我检查了区分大小写,并使用AVAudioPlay和SystemSound尝试播放文件,但即使振动也不起作用。 AudioToobox and AVfoundation are imported in .h. AudioToobox和AVfoundation以.h导入。 The audio plays with both methods on the iOS simulator. 音频在iOS模拟器上播放两种方法。

Heres the code using SystemSound: 下面是使用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);}

And with AVAudioPlayer: 并使用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];}

By the way, the variable al sets to 0 after it plays. 顺便说一下,变量al在播放后设置为0。 Is my coding wrong to have the sound and vibrate work on the device itself? 我的编码是否错误,让设备本身的声音和振动工作? Is there a specific type of .wav file that needs to be played? 是否需要播放特定类型的.wav文件? Any help would be appreciated. 任何帮助,将不胜感激。

I was running into this same issue. 我遇到了同样的问题。 There is actually a second volume setting specially for alerts that at least in my case was set to mute, even though my regular volume was up. 实际上有第二个音量设置专门用于警报,至少在我的情况下被设置为静音,即使我的常规音量已经达到。 Take a look under the sounds menu in the Settings app on the device and turn that up. 在设备上的“设置”应用中查看声音菜单,然后将其调高。

You probably don't want to use the alerts for an actual released app though if it is important that the sound actually play, since it will require users to make sure this separate audio setting is up. 您可能不希望将警报用于实际发布的应用程序,但重要的是声音实际播放,因为它将要求用户确保此单独的音频设置已启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 背景音频在iOS模拟器上可运行,但不能在设备上运行 - background audio working on iOS simulator but not device 音频文件可在iOS模拟器中运行,但无法在实际设备上找到 - Audio files working in iOS simulator, but can't be found on actual device 音频播放器可在模拟器中工作,但不能在iOS设备上工作 - Audio player works in simulator but not on iOS device Tabbarcontroller在模拟器上工作而不在iOS设备上 - Tabbarcontroller is working in simulator not on iOS device UIImagePickerController在iOS设备上工作但在iOS模拟器上没有? - UIImagePickerController working on iOS device but not on iOS simulator? free()使用iOS Simulator,但不能在实际设备上使用 - free() working with iOS Simulator but not on real device 本地通知可在ios模拟器上运行,但不能在设备上运行 - Local notifications working on ios simulator but not on device 屏幕截图代码可以在Simulator中完美运行,但不能在iOS Device中运行 - Screenshot code working perfectly in Simulator but not in iOS Device 自动旋转仅在设备上的模拟器中有效(IOS 7.1) - Autorotation only working in simulator not on device (IOS 7.1) wsdl2objc在ios 6.0模拟器上不起作用,但在ios 5设备上起作用 - wsdl2objc is not working on ios 6.0 simulator but works on ios 5 device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM