Search Results

Search found 1 results on 1 pages for 'bucche'.

Page 1/1 | 1 

  • How stop mp3 playing started with audioplayer

    - by bucche
    Hi, My application consists of a table view. row1, row2, row3.... When a cell is touched a different mp3 starts to play (row1.mp3, row2.mp3, row3.mp3....). it works! but i have a problem: i am not able to stop previous mp3, so if i touch a second cell i have 2 mp3s playing... if i touch a third cell i have 3 mp3s and so on... i want to stop mp3 that started before and play mp3 that is related to touched cell... during my tries, i created a variable to show some alerts if the player plays or not and when i am "inside the if" i used [myAudioPlayer stop].. i see the correct alert but mp3 doesn't stop. here is my code - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSArray *elementi = [[array objectAtIndex:indexPath.row] componentsSeparatedByString:@"|"]; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.mp3", [[NSBundle mainBundle] resourcePath],[elementi objectAtIndex:1]]]; NSError *error; myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; myAudioPlayer.numberOfLoops = -1; if (inEsecuzione == 0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"1" message:@"1" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil]; [alert show]; [alert release]; [myAudioPlayer play]; inEsecuzione = 1; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"2" message:@"2" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil]; [alert show]; [alert release]; [myAudioPlayer stop]; inEsecuzione = 0; } } as i wrote before, i am not able to stop previous mp3

    Read the article

1