我正在为电影歌手写一个小的音板应用程序,我是iPhone SDK的新手
我已使用以下代码将所有按钮链接到他们的Mp3文件,但只有部分按钮播放他们的声音?
我检查了所有文件名,它们都匹配代码:
- (IBAction)canWeBeAlone:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Can We Be Alone", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)itsThreeAM:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Its 3AM", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)iHaveSinned:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"I Have Sinned", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)mowMyLawn:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Mow My Lawn", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)theyAreMyFriends:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"They Are My Friends", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)itsSteve:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Its Not Jeffy Its Steve", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (IBAction)itWasWrongOfMe:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLRef;
soundfileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"It Was Wrong of Me", CFSTR ("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundfileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
任何帮助都会受到赞赏
答案 0 :(得分:0)
我相信您应该使用AVAudioPlayer播放MP3文件而不是AudioServicesPlaySystemSound。 AVAudioPlayer支持播放“...同时发出多个声音,每个音频播放器发出一个声音,具有精确同步”。请参阅AVAudioPlayer类参考。这里还有一个项目的链接,显示你如何使用AVAudioPlayer:[http://www.techotopia.com/index.php/Playing_Audio_on_an_iPhone_using_AVAudioPlayer_(iOS_4)] [1]