从UIPicker更改音频文件
|
我设置了“ 0”并运行良好。当用户选择一行时,我希望一个音频文件开始,但是如果用户在第一个音频文件停止播放之前选择了另一行,我希望它停止第一个音频文件,然后播放新的音频文件。
我现在可以使用下面的代码来实现,但是两个文件同时播放,而我找不到停止第一个文件的方法。
我要走错路了吗? (我是SDK编码的新手)
任何想法,将不胜感激
谢谢
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component{
return [list count];
}
-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [list objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *string = [NSString stringWithFormat:@\"%@\", [list2 objectAtIndex:row]];
pickLabel.text = string;
if(row == 1){
NSString *path = [[NSBundle mainBundle]
pathForResource:@\"del08sample\"ofType:@\"mp3\"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
else if (row == 2){
NSString *path = [[NSBundle mainBundle]
pathForResource:@\"icgi03sample\"ofType:@\"mp3\"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[theAudio play];
}
}
没有找到相关结果
已邀请:
1 个回复
扫窟