AVAudio播放器总是零

时间:2016-05-28 23:56:39

标签: ios objective-c avaudioplayer

我不确定为什么我的AVAudioPlayer总是

#import <AVFoundation/AVFoundation.h>
@property (nonatomic) AVAudioPlayer *audioPlayer;
@synthesize audioPlayer;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Construct URL to sound file
    NSString *path = [NSString stringWithFormat:@"%@/background-music-aac.caf", [[NSBundle mainBundle] resourcePath]];
    NSURL *soundUrl = [NSURL fileURLWithPath:path];

    // Create audio player object and initialize with URL to sound
    NSError *audioError = nil;
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:&audioError];
    if (audioPlayer == nil) {
        NSLog(@"Error? %@", audioError);
        NSLog(@"AudioPlayer: %@", audioPlayer.description);
    }

我觉得我已将此设置正确,但它不起作用,我nil获得了null / audioPlayer

1 个答案:

答案 0 :(得分:0)

.caf文件是问题,感谢Brandon的帮助