2016-11-24 79 views
0

Iam使用AVAudioplayer,我想暂停音乐几秒,当按下按钮时,并在6秒后,我想音乐开始播放而不按任何按钮。这甚至有可能吗?如果是这样,我该怎么做? 这里是我的代码示例:暂停AVAudioplayer几秒

NSString *soundPath2 =[[NSBundle mainBundle] pathForResource:@"background" ofType:@"wav"]; 

NSURL *soundURL2 = [NSURL fileURLWithPath:soundPath2]; 
NSError *error2 = nil; 
self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL2 error:&error2]; 

self.backgroundMusic.numberOfLoops = 9; 
[self.backgroundMusic prepareToPlay]; 
[self.backgroundMusic play]; 

回答

0

我不知道是不是这样做的正确的方式,但我这样做

[self.backgroundMusic pause]; 
[NSTimer scheduledTimerWithTimeInterval:6.0 
           target:self 
           selector:@selector(continuePlay) 
           userInfo:nil 
           repeats:NO]; 
       ......................... 

-(void)continuePlay{ 
[self.backgroundMusic play]; 
} 

,如果我错了,请大家指正!