如何在播放另一种声音之前停止声音?

时间:2014-04-19 05:36:03

标签: uitableview ios7

.h文件

 #import <UIKit/UIKit.h>
 #import <AudioToolbox/AudioToolbox.h>
 @interface WUARingtone : UIViewController<UITableViewDelegate,UITableViewDataSource>{

SystemSoundID toneSSIDs[10];

}

@end

.m文件

我已经采用了一系列歌曲名称。

   _nma_RingtoneName = [[NSMutableArray alloc]initWithObjects:@"Bird",@"Chicken",@"Digital",@"Extreme",@"Melody",@"Mixer",@"Morning",@"Simple",@"Siren",@"Smooth",@"Soft", nil];

表视图委托方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
  NSString *CellIdentifier = @"Cell";
WUACellForRingtones *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    [tableView registerNib:[UINib nibWithNibName:@"WUACellForRingtones" bundle:Nil] forCellReuseIdentifier:CellIdentifier];
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}

cell.songName.text = [_nma_RingtoneName objectAtIndex:indexPath.row];
cell.imageView.image= [UIImage imageNamed:@"music.png"];
return cell;
}

选择了方法:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
int ringIndex =(int) [defaults integerForKey:@"ringtoneindex"];



NSString *toneFilename = [_nma_RingtoneName objectAtIndex:indexPath.row];

NSURL *toneRef = [[NSBundle mainBundle]URLForResource:toneFilename withExtension:@"mp3"];

SystemSoundID toneSSID = 0;

if (indexPath.row != ringIndex)
{
    SystemSoundID toneID = ringIndex;
    AudioServicesDisposeSystemSoundID(toneID);
}

AudioServicesCreateSystemSoundID((__bridge CFURLRef) toneRef, &toneSSID);


[defaults setInteger:indexPath.row forKey:@"ringtoneindex"];
toneSSIDs[indexPath.row] = toneSSID;



AudioServicesPlaySystemSound(toneSSID);
}

一个声音正在播放而我被选中另一个声音正在播放但是我希望第一个声音关闭再播放另一个声音

0 个答案:

没有答案