【问题标题】:Playing Multiple MP3 files with Multiple Buttons - iPhone SDK - xCode使用多个按钮播放多个 MP3 文件 - iPhone SDK - xCode
【发布时间】:2013-01-01 02:10:18
【问题描述】:

我正在为 Movie The ringer 编写一个小型音板应用程序,我是 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);

}

任何帮助将不胜感激

【问题讨论】:

    标签: iphone xcode sdk ios6


    【解决方案1】:

    我认为您应该使用 AVAudioPlayer 来播放 MP3 文件,而不是使用 AudioServicesPlaySystemSound。 AVAudioPlayer 支持“...同时播放多个声音,每个音频播放器一个声音,精确同步”。请参阅 AVAudioPlayer 类参考。这里还有一个项目链接,展示了如何使用 AVAudioPlayer:[http://www.techotopia.com/index.php/Playing_Audio_on_an_iPhone_using_AVAudioPlayer_(iOS_4)][1]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 2010-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多