我不确定为什么我的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
。
答案 0 :(得分:0)
.caf文件是问题,感谢Brandon的帮助