音频无法在iOS 8中播放

时间:2014-09-29 00:15:03

标签: ios objective-c iphone

我有这个代码来获取我的项目中的音频并且应该播放音频:

#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模拟器,这段代码不起作用,我听不到音频,为什么?

0 个答案:

没有答案