这是我所拥有的:
-(void)awakeFromNib {
NSString *path = [[NSBundle mainBundle] pathForResource:***AUDIOFILE*** ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
[theAudio play];
编码很好,除非我不知道如何调出资源播放声音或其他。
最佳答案
如果您的音频文件在您的项目中,则只需给文件名而不带扩展名即可代替 * 音频文件 * 。
对AVAudioPlayer使用[theAudio prepareToPlay]
方法是一个好习惯。
关于iphone - 如何自动播放音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198724/