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