简体   繁体   English

AVAudioPlayer错误与M4A但不是mp3

[英]AVAudioPlayer error with m4a but not mp3

I'm pretty confused by this one and can't think of anything obvious that I am doing wrong. 我对此感到非常困惑,无法想到我做错了任何明显的事情。

I can't get iOS to pull an m4a out of my app bundle 我无法让iOS从我的应用程序包中拉出m4a

eg 例如

NSURL *clickurl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/fishy2.m4a", [[NSBundle mainBundle] resourcePath]]];

NSError *error;

audioPlayer = [[AVAudioPlayer alloc] 
                   initWithContentsOfURL:clickurl
                   error:&error];

audioPlayer.delegate = self;

if (error)
        NSLog(@"Error: %@", 
              [error localizedDescription]);
else
        [audioPlayer play];

I get an error -43 我收到错误-43

However, if I instead use an identical mp3 instead 但是,如果我改为使用相同的mp3代替

NSURL *clickurl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/fishy.mp3", [[NSBundle mainBundle] resourcePath]]];

everything is happy 一切都快乐

I've tried this many many times across different projects and can't see where I'm going wrong. 我在不同的项目中尝试了很多次,看不到我要去哪里。 I've been using NSFileManager to check if it is there and it says no to the m4a, but yes to the mp3. 我一直在使用NSFileManager来检查它是否在那里,它对m4a说不,对mp3说是。 Tried this with all manner of different methods of importing different audio files in different formats and I can't seem to get it to find the m4a (and it really really has to be m4a). 尝试了各种方式以不同的方法导入不同格式的不同音频文件,但我似乎找不到它来找到m4a(实际上确实必须是m4a)。 mp3, wav, caf etc... all work. mp3,wav,caf等...全部正常。 Interestingly, the m4as that I run from the user documents directory work just fine 有趣的是,我从用户文档目录运行的m4as正常工作

All I want is to be able to copy the file! 我想要的就是能够复制该文件!

Any ideas at all? 有什么想法吗?

解决方法=右键单击并“将文件添加到”而不是拖动

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

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