0
首先,我对客观的C相当新。我想在特定条件下播放声音和振动。我的iPhone 4未静音,我检查了大小写,并使用AVAudioPlay和SystemSound尝试播放文件,但即使振动也不起作用。 AudioToobox和AVfoundation在.h中导入。音频在iOS模拟器上使用这两种方法播放。模拟器中的音频和振动工作不在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];}
顺便说,可变人它起着后设置为0。声音和振动对设备本身有效吗?我的编码是错误的吗?是否需要播放特定类型的.wav文件?任何帮助,将不胜感激。
那么有没有办法在关闭设置的同时转动播放振动?除非我们提示用户打开振动... – Denis
尴尬,但这是我的问题!感谢您的高举。 :) – Groot