0

サウンド ファイルの再生に問題があります。複数のボタンがあり、それぞれがサウンド ファイルに関連付けられています。たとえば、サウンド n.1 が鳴っているときに、ボタンを押してサウンド n.2 を開始すると、2 つのサウンドが重なります。各ボタンが押されたときに、他のボタンで再生されるオーディオを停止したい。これが私の .h ファイルと私の .m ファイルの一部です。「 if 」を試してみましたが、「宣言されていない識別子の使用」エラーが表示されます。全くの初心者ですので、よろしくお願いします。

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <AVAudioPlayerDelegate> {}

-(IBAction)playSound1;
-(IBAction)playSound2;

@end

@implementation ViewController

-(IBAction)playSound1{
    NSString *path=[[NSBundle mainBundle] pathForResource:@"12-Toxicity" ofType:@"mp3"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]error:NULL];
    theAudio.delegate=self;
    [theAudio play];

}

@end
4

1 に答える 1