このフォーラムを含む複数のフォーラムを検索しましたが、問題の解決策が見つかりません。「IQTest」ビュー コントローラのロード時に再生するように設定されたサウンド ファイルがあります。正常に再生され、「IQTest」ビュー コントローラーでサウンドを停止できます。
IQTest.h
@interface IQTest : UIViewController
{
AVAudioPlayer *theAudio;
}
@property (nonatomic, strong) AVAudioPlayer *theAudio;
@end
IQTest.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"IQTestBackgroundMusic" ofType:@"mp3"];
AVAudioPlayer* soundTrack=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
soundTrack.numberOfLoops = -1;
self.theAudio = soundTrack;
[theAudio play];
}
ユーザーが「IQTestQuestionThree」のビュー コントローラーでボタンを押したときにサウンドの再生を停止したいのですが、サウンドを停止しようとすると、再生が続くか、アプリがクラッシュします。複数の方法を試しましたが、音を止める方法はまだ見つかりません。
IQTestQuestionThree.m
- (IBAction) question3Answer1
{
IQTest *IQTestAudio = [[IQTest alloc] init];
[IQTestAudio.theAudio stop];
iqScaryFace.hidden = NO;
homeButton.hidden = NO;
homeButtonLabel.hidden = NO;
answer1Button.hidden = YES;
answer2Button.hidden = YES;
answer3Button.hidden = YES;
answer4Button.hidden = YES;
}
私が得ることができる助けをありがとう。