[英]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.