Audio File continues to play even on leaving the view

Posted by Swastik on Stack Overflow See other posts from Stack Overflow or by Swastik
Published on 2011-01-13T03:50:25Z Indexed on 2011/01/13 3:53 UTC
Read the original article Hit count: 171

Filed under:

What I am doing is

-(void)viewWillAppear:(BOOL)animated{

[NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(clickEvent:) userInfo:nil repeats:YES]; }

-(void)clickEvent:(NSTimer *)aTimer{

NSDate* finishDate = [NSDate date];

if([finishDate timeIntervalSinceDate: self.startDate] > 11 && touched == NO){

NSString *mp3Path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.mp3"]; [self playMusicFile:mp3Path]; NSLog(@"Timer from First Page"); [aTimer invalidate]; //[touchCheckTimer release]; aTimer = nil;

}

else{

}

-(void)playMusicFile:(NSString *)mp3Path{

NSURL *mp3Url = [NSURL fileURLWithPath:mp3Path]; NSError *err; AVAudioPlayer *audPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mp3Url error:&err]; [self setAudioPlayer1:audPlayer]; if(audioPlayer1) [audioPlayer1 play];

[audPlayer release];

}

Now, on pushing another view this audio file keeps playing in the background. Please help!

© Stack Overflow or respective owner

Related posts about iphone-sdk-4.0