问题描述
|
我没有声音,并且在构建时出现此错误(尝试设置(空)音频设备的采样率时出现错误“!dat”)。音乐文件有问题还是代码。
Nsstring *playM = [[NSBundle mainBundle] pathForResource:@\"wildM\" ofType:@\"m4a\"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:playM];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
[player preparetoPlay];
player.currentTime = 0;
[player play];
解决方法
我有同样的问题。这是我所做的:
关闭xcode和iOS模拟器
拔下您可能拥有的耳机插孔和任何USB耳机
重新启动xcode并运行仿真(问题应解决)
重新插入您要使用的任何音频设备
,代码看起来还可以。您不必调用prepareToPlay,它只是缓冲内容...也不需要设置currentTime。您的m4a文件编码错误的可能性更大。