我有这个代码来获取我的项目中的音频并且应该播放音频:
#import "ViewController.h"
#import <AudioToolbox/AudioServices.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self playAudio];
}
- (void)playAudio {
[self playSound:@"Splash" :@"wav"];
}
- (void)playSound :(NSString *)fName :(NSString *) ext{
SystemSoundID audioEffect;
NSString *path = [[NSBundle mainBundle] pathForResource : fName ofType :ext];
if ([[NSFileManager defaultManager] fileExistsAtPath : path]) {
NSURL *pathURL = [NSURL fileURLWithPath: path];
AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &audioEffect);
AudioServicesPlaySystemSound(audioEffect);
}
else {
NSLog(@"error, file not found: %@", path);
}
}
@end
我正在使用iOS 8和iPhone 4s模拟器,这段代码不起作用,我听不到音频,为什么?