听不到AVAudioPlayer的声音?

时间:2016-01-02 20:31:29

标签: objective-c iphone avaudioplayer

无法弄清楚这里有什么问题,或者我听不到听到的声音。它构建良好,没有错误。

从我正在阅读的内容来看,它与ARC有关......? 但是,当我查看"构建设置: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字符串参数&#39 ;
...所以看着我看不到文件名...文件名:(null)

1 个答案:

答案 0 :(得分:0)

不得不转到:

Project:
Targets:
Build Phases:
Copy Bundle Resources: and add the abc.m4a file to it.

除了那个之外,我需要的其他文件就在那里。

更多信息:NSBundle pathForResource is NULL