AVAudio 播放器始终为零
AVAudio player always nil
我不确定为什么我的 AVAudioPlayer
总是 nil?
#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
.
问题出在 .caf 文件上,感谢 Brandon 的帮助
我不确定为什么我的 AVAudioPlayer
总是 nil?
#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
.
问题出在 .caf 文件上,感谢 Brandon 的帮助