播放声音按钮(AV音频播放器)返回nil字符串参数 [英] Playing Sound On Button (AV Audio Player) returning nil string parameter

查看:169
本文介绍了播放声音按钮(AV音频播放器)返回nil字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图播放按钮preSS声音。 previously,我用Audiotoolbox这只是正常工作使用相同的文件类型。但是,我需要改变使用AvAudioPlayer监守它不使用的铃声音量。

I am attempting to play a sound on button press. Previously, I used Audiotoolbox which worked just fine with the same file type. However, i need to change to using AvAudioPlayer becuase it doesn't use the ringer volume.

所以上周我开发使用音频播放器上播放的点击声音的理解。我曾在我的应用程序上使用的精确同一code工作一种享受。但是,这个应用程序试图尽管不计其数的时间将不会与AVFoundation / AudioPlayer工作。我曾尝试添加新文件,新的按钮,改变文件的扩展名。文件名的是资源文件夹即可。我的不可以拼写的名字写错了。

So last week I developed an understanding of using the audio player to play a sound on click. I had it working a treat on my over app using the exact same code. However, this app despite trying countless time will not work with AVFoundation/AudioPlayer. I have tried adding new files, new buttons, changes the extension of the files. the file names are in the resources folder. I have not spelt the name wrong.

确切的问题是它试图找到我的文件,我想,当返回一个零字符串参数:

The exact problem is it is returning a nil string parameter when trying to find my file i guess:

终止应用程序由于未捕获的异常
  NSInvalidArgumentException'的,理由是: * 的 - [NSURL
  initFileURLWithPath:]:零字符串参数

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string parameter'

我已经看过的几乎每个论坛上发帖这个,但其中没有一个会帮助我。我只能想到孤单在我的项目潜在的问题也许是资源文件夹而不是实际的AVAudioPlayer code由于这一事实,我有这个确切的code工作一样的另一个项目。任何帮助将是非常美联社preciated因为我难住了。

I have looked on just about every forum post about this but none of which will help me. I can only think theres an underlying problem in my project maybe the resources folder not the actual AVAudioPlayer code due to the fact i had this exact code working the same on another project. Any help would be much appreciated as I am stumped.

下面是其中的重要code:

Here is the important code:

这是我的.h

@interface MainViewController : UIViewController

@property (strong, nonatomic) AVAudioPlayer *theAudio;
- (IBAction)test:(id)sender;

这是在我的.m

@synthesize theAudio;

- (IBAction)test:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"beast" ofType:@"wav" ];
self.theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]      error:nil];
[self.theAudio play];
}

请帮助

推荐答案

返回零路径[一个NSBundle pathForResource:ofType:] 表示wav文件一直没有复制到您的应用程序包。

The nil path returned by [NSBundle pathForResource:ofType:] means that the wav file has not been copied into your app package.

你有没有添加文件到您的项目?如果是这样,包括在你的目标的文件吗?
检查目标>构建阶段>复制包资源或项目导航器(⌘1)选择它们并选中在文件检查器(⌘⌥1)。

Have you added the files to your project? If so, are the files included in your target? Check in Target > Build Phases > Copy Bundle Resources or select them in the project navigator (⌘1) and check the box in the File Inspector (⌘⌥1).

这篇关于播放声音按钮(AV音频播放器)返回nil字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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