1

.h file

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

SystemSoundID toneSSIDs[10];

}

@end

.m file

i have taken one array of song name.

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

table view delegate method :

- (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;
}

did select method :

 -(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);
}

one sound is playing while i am selected another one both are playing but i want first one is off and play another one

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Priyank Gandhi
  • 626
  • 2
  • 8
  • 21
  • AudioServicesDisposeSystemSoundID(toneID) should be all you need to stop the current running sould. Try debugging the app and ensure that the last song is properly getting disposed. – remudada Apr 19 '14 at 06:38
  • This seems like what you are looking for http://stackoverflow.com/questions/5765595/stop-a-sound-using-the-same-button-that-plays-it – remudada Apr 19 '14 at 06:39
  • where to i put AudioServicesDisposeSystemSoundID(toneID) than i stop voice play another sound @remudada – Priyank Gandhi Apr 19 '14 at 08:27

0 Answers0