我是 Objective-c 和其他环境的绝对初学者,所以请耐心等待。这是我的问题:我需要播放声音文件,以便它们在另一个启动时停止,现在它们重叠;这是我的代码片段。提前感谢您,如果您需要其他详细信息,请告诉我。
- (IBAction)soundfirst {
NSString *path =
[[NSBundle mainBundle] pathForResource:@"hi2" ofType:@"mp3"];
player1 = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
player1.delegate = self;
[player1 play];
}
- (IBAction)soundsecond {
[player1 stop];
NSString *path =
[[NSBundle mainBundle] pathForResource:@"hi2" ofType:@"mp3"];
player2 = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
player2.delegate = self;
[player2 play];
}