尝试实例化AVAudioPlayer时,NSBundle找到mp3文件但找不到m4a [英] NSBundle finds mp3 file but not m4a when trying to instantiate AVAudioPlayer

查看:103
本文介绍了尝试实例化AVAudioPlayer时,NSBundle找到mp3文件但找不到m4a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序,应该可以播放音频文件.每当我将mp3文件加载到NSURL时,都可以正常工作,并且AVAudioPlayer可以播放歌曲.但是,当我更改为m4a文件时,NSString路径返回nil,就像它找不到我的文件的路径一样,因此未形成NSURL. m4a文件当然在项目中.它遵循下面的代码,但我认为这不是代码问题.有什么想法吗?谢谢.

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. 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. The m4a file is of course there, in the project. 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文件未在复制捆绑资源"阶段组下列出,请添加该文件,然后进行清洁"并再次运行.

Check your Target's Build Phases, if your m4a file is not listed under Copy Bundle Resources phase group, add it, then Clean, and Run again.

这篇关于尝试实例化AVAudioPlayer时,NSBundle找到mp3文件但找不到m4a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆