我AVAudioplayer
用来播放音频文件,播放/暂停按钮在播放和暂停之间切换,以及一个NSTimer
接一个audio player
地同步view controllers
。我总共有 10 或 11 个view controllers
要一个接一个地加载。
当播放按钮第一次被按下时,它NSTimer
开始播放,audio file
并且基于NSTimer
,视图控制器将一个接一个地加载。当再次按下暂停按钮以恢复时,它会从该点音频文件恢复所有内容,NSTimer
并view controllers
从暂停的同一点恢复,这很好。但是,同时它开始view controllers
从头开始一个接一个地加载,NSTimer
这是不好的。
它正在使用此语句重新加载视图控制器
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
view controllers
所以我的问题是,当再次按下暂停按钮以恢复播放时,我需要从头开始再次停止加载。
-(void)playpauseAction:(id)sender
{
if ([audioPlayer isPlaying]) {
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
} else {
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
}
}
-(void)pauseTimer{
pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];
previousFireDate = [[timer fireDate] retain];
[timer setFireDate:[NSDate distantFuture]];
}
-(void)resumeTimer{
float pauseTime = -1*[pauseStart timeIntervalSinceNow];
[timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];
[pauseStart release];
[previousFireDate release];
}
- (void)displayviewsAction:(id)sender
{
First *firstController = [[First alloc] init];
firstController.view.frame = CGRectMake(0, 0, 320, 480);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1];
[transitionAnimation setType:kCATransitionFade];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
[self.view addSubview:firstController.view];
[self.view addSubview:toolbar];
[firstController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];
}
view controllers
当再次按下暂停按钮以恢复播放时,任何人都可以提供有关如何从头开始再次停止加载的想法。