【发布时间】:2014-09-21 22:20:32
【问题描述】:
这是我的 .m 文件中的内容,来自 xcode。 我的主要目标是让一个按钮在附加了 2 个声音文件和一个随机发生器时播放声音(不是同时),这样它就不会两次播放相同的声音,或者不太可能播放两次。我运行代码,当我单击“是”按钮时,会发生 lldb NSEsception 错误。我四处寻找 lldb 异常错误,但我找到的解决方案是进入视图控制器并删除带有黄色感叹号的任何内容;这并没有解决问题..
#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController ()
@end
@implementation ViewController : UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Yes{
NSMutableArray *array=[NSMutableArray
arrayWithObjects:
@"yes.mp3",
@"yes 3.mp3",
nil];
int i=0;
for(i=0;i<=[array count]; i++)
{
NSInteger rand=(arc4random() %1);
[array exchangeObjectAtIndex:i
withObjectAtIndex:rand];
}
NSString *sound = [array objectAtIndex:i];
AVAudioPlayer* audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle]pathForResource:sound ofType:@"mp3"]] error:NULL];
[audioPlayer play];
}
@end
【问题讨论】:
标签: ios objective-c iphone uiviewcontroller