我是一個絕對的初學者,在objective-c和其他環境中,請耐心等待。這是我的問題:我需要播放聲音文件,以便每個聲音文件在另一個聲音文件啓動時停止,現在它們重疊;這裏是我的代碼片段。 預先感謝您,讓我知道您是否需要其他細節。第二次播放時停止第一個聲音
- (IBAction)soundfirst {
NSString *path =
[[NSBundle mainBundle] pathForResource:@"hi2" ofType:@"mp3"];
player1 = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
player1.delegate = self;
[player1 play];
}
- (IBAction)soundsecond {
[player1 stop];
NSString *path =
[[NSBundle mainBundle] pathForResource:@"hi2" ofType:@"mp3"];
player2 = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:path]
error:NULL];
player2.delegate = self;
[player2 play];
}
非常感謝你,我會試着去看看它是否有效。儘管如此,謝謝你。 –
聽起來不錯,讓我知道如果有任何問題。 –
嗨再次Khanh,抱歉打擾你,但我現在有一個新問題:昨天你的解決方案工作,但我想讓代碼更簡單,更少混亂。所以現在當我嘗試使用「if」時有這個問題:使用未聲明的標識符「playsound2」。我可以在哪裏發佈代碼而不會產生新的問題?先謝謝你。 N. –