【发布时间】:2014-10-05 18:51:03
【问题描述】:
好的,所以代码假设在第一次单击按钮时播放声音文件,并在再次单击相同按钮时播放另一个声音。我把所有 mp3 的声音文件放在一个文件夹中,它只播放文件是的(我还有其他声音,比如你好,你好,但是当我把它放在 pathforresouce 中时它不会播放它们),我得到一个 nse 异常错误当我第二次单击按钮播放第二个声音时(进入构建阶段并且声音文件夹在那里但它没有在其他音频文件中播放,只有它播放?)。因此,我取出了两个文件的资源位置路径,以检查我的声音文件是否正常工作并且它仍在播放 yes 文件。当 yes 文件仅位于该声音文件夹中的一个位置时,这怎么可能?我什至从我的整个项目中取出了那个声音文件夹,它仍然在播放,没有声音文件,也没有资源路径?
#import <AVFoundation/AVAudioPlayer.h>
#import "ViewController.h"
@interface ViewController ()
@end
int flag;
@implementation ViewController
AVAudioPlayer *theAudio;
- (IBAction)Yes:(id)sender {
if(flag==0){
//play file one on first button click
theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];
[theAudio play];
flag=1;
}
else if(flag==1)
{
//play file second on first button click
theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];
[theAudio play];
flag=0;
}
}
@end
【问题讨论】:
-
您的问题解决了吗?
标签: objective-c xcode