简体   繁体   English

在尝试实例化AVAudioPlayer时,NSBundle找到mp3文件而不是m4a

[英]NSBundle finds mp3 file but not m4a when trying to instantiate AVAudioPlayer

I have a simple app that is supposed to play a audio file. 我有一个应该播放音频文件的简单应用程序。 Whenever I load a mp3 file to my NSURL is works fine and the AVAudioPlayer gets to play the song. 每当我加载一个mp3文件到我的NSURL工作正常,AVAudioPlayer播放这首歌。 However, when I change to a m4a file, the NSString path returns nil, like it is not able to find the path to my file, and thus the NSURL is not formed. 但是,当我更改为m4a文件时,NSString路径返回nil,就像它无法找到我的文件的路径,因此没有形成NSURL。 The m4a file is of course there, in the project. 当然,m4a文件存在于项目中。 It follows below the code, but I don't think is a code issue. 它遵循下面的代码,但我不认为是代码问题。 Any ideias? 任何想法? Thanks. 谢谢。

NSString *path = [[NSBundle mainBundle] pathForResource:@"end" ofType:@"m4a"];
NSURL *urlFile = [NSURL fileURLWithPath:path];
NSError *error;
soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlFile error:&error];
if (error)
{
    NSLog(@"Error in audioPlayer: %@",[error localizedDescription]);
} else {
    soundPlayer.delegate = self;
    [soundPlayer prepareToPlay];
    [soundPlayer play];
}

检查目标的构建阶段,如果您的m4a文件未列在“复制捆绑资源”阶段组下,请添加,然后清除,然后再次运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM