单击按钮后,我已经尝试了几个小时播放简单的声音,但我无法做到。在尝试了几个教程之后,我在这个链接中关注了一个:
这是 .h 文件:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface soundTestViewController : UIViewController{
}
-(IBAction) playSound;
@end
这是 .m 文件:
#import "soundTestViewController.h"
@implementation soundTestViewController
-(IBAction) playSound{
CFBundleRef mainBundle=CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"mysound", CFSTR("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
但是,构建结果给出了错误:
Build soundTest of project soundTest with configuration Debug
Ld build/Debug-iphonesimulator/soundTest.app/soundTest normal i386
cd /Users/joegeneric/Documents/soundTest
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest -filelist /Users/joegeneric/Documents/soundTest/build/soundTest.build/Debug-iphonesimulator/soundTest.build/Objects-normal/i386/soundTest.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -o /Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator/soundTest.app/soundTest
ld: warning: in /Users/joegeneric/Documents/soundTest/AVFoundation.framework/AVFoundation, missing required architecture i386 in file
ld: warning: in /Users/joegeneric/Documents/soundTest/AudioToolbox.framework/AudioToolbox, missing required architecture i386 in file
Undefined symbols:
"_AudioServicesPlaySystemSound", referenced from:
-[soundTestViewController playSound] in soundTestViewController.o
"_AudioServicesCreateSystemSoundID", referenced from:
-[soundTestViewController playSound] in soundTestViewController.o
ld: symbol(s) not found
你能展示我做错了什么或任何其他更简单的关于在 iPhone SDK 中播放声音的工作教程吗?