听不到 AVAudioPlayer 的声音?
Not hearing sound from AVAudioPlayer?
无法弄清楚这里出了什么问题,或者我听不到声音。它构建良好,没有错误。
根据我正在阅读的内容,它与 ARC 有关....?
但是当我查看 "Build Settings: Apple LLVM 7.0: ARC" ARC 时,它被列为 "NO"
.h
@property (nonatomic, strong) AVAudioPlayer *player;
.m
@synthesize player;
...
NSURL *soundFileURL = [[NSBundle mainBundle] URLForResource:@"abc" withExtension:@"m4a"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //Infinite
[player play];
这个有效:
AudioServicesPlaySystemSound(1005);
试试这个:(ARC __bridge modifiers demystified)
SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"m4a"];
NSLog(@"Filename: %@", soundFile);
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundFile], & soundID);
AudioServicesPlaySystemSound(soundID);
这会崩溃:* 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'* -[NSURL initFileURLWithPath:]: nil string parameter'
...所以在查看时我看不到文件名...文件名:(null)
必须转到:
Project:
Targets:
Build Phases:
Copy Bundle Resources: and add the abc.m4a file to it.
除那个文件外,我需要的其他文件都在那里。
更多信息:NSBundle pathForResource is NULL
无法弄清楚这里出了什么问题,或者我听不到声音。它构建良好,没有错误。
根据我正在阅读的内容,它与 ARC 有关....? 但是当我查看 "Build Settings: Apple LLVM 7.0: ARC" ARC 时,它被列为 "NO"
.h
@property (nonatomic, strong) AVAudioPlayer *player;
.m
@synthesize player;
...
NSURL *soundFileURL = [[NSBundle mainBundle] URLForResource:@"abc" withExtension:@"m4a"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //Infinite
[player play];
这个有效:
AudioServicesPlaySystemSound(1005);
试试这个:(ARC __bridge modifiers demystified)
SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"m4a"];
NSLog(@"Filename: %@", soundFile);
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundFile], & soundID);
AudioServicesPlaySystemSound(soundID);
这会崩溃:* 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'* -[NSURL initFileURLWithPath:]: nil string parameter'
...所以在查看时我看不到文件名...文件名:(null)
必须转到:
Project:
Targets:
Build Phases:
Copy Bundle Resources: and add the abc.m4a file to it.
除那个文件外,我需要的其他文件都在那里。
更多信息:NSBundle pathForResource is NULL