2016-11-24 6 views
0

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]; 
} 

をしました!

関連する問題