开发者

Audio File continues to play even on leaving the view

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 *)a开发者_Python百科Timer{

 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!


Well it is very common mistake

when you are leaving the view call stop method on the AVAudioPlayer variable pointer that you used to play the audio with

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜