我有一個用戶移動一個對象,當移動結束時它將更新顯示並播放聲音。這一切都很好,但我不希望播放視圖時播放聲音。我如何避免這種情況發生?我需要在viewDidLoad中添加一些東西嗎?這是觸發事件的代碼。謝謝你的幫助。 `想要保持播放視圖時播放聲音
// Updates the text field with the current rotation angle and play sound.
- (void) updateTextDisplay
{
NSError *error = nil;
if (imageAngle >=0 && imageAngle <=180){
ComplimentPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"nice" ofType:@"m4a"]] error:&error];
ComplimentPlayer.delegate = self;
textDisplay.text = [NSString stringWithFormat:@"blah blah blah"];
} else if (imageAngle >180 && imageAngle <=360){
ComplimentPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"good" ofType:@"m4a"]] error:&error];
ComplimentPlayer.delegate = self;
textDisplay.text = [NSString stringWithFormat:@"blah blah"];
}
NSTimeInterval playbackDelay = 0.5;
[ComplimentPlayer playAtTime: ComplimentPlayer.deviceCurrentTime + playbackDelay];
} `
謝謝,我會給你一個鏡頭。 – mmoore410 2012-02-29 23:37:49