【发布时间】:2016-01-02 20:31:28
【问题描述】:
无法弄清楚这里出了什么问题,或者我听不到什么声音。它构建良好,没有错误。
从我所读的内容来看,它与 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 string parameter”
...所以看我看不到文件名...文件名:(空)
【问题讨论】:
-
尝试这样获取声音的路径url: NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"m4a"]; NSURL * soundFileURL = [NSURL fileURLWithPath:soundFilePath];
-
@azimov 为什么? OP获取URL的代码很好。
-
如何以及在哪里声明播放器。您必须在使用时保留播放器。例如通过强大的属性
-
在财产方面做了“强”,但什么也没做。也许暂停一个线程? ... 试过了,什么都没有。
标签: objective-c iphone avaudioplayer