0

私は2つのView Controllerを持っています:

MainMenuView:

- (void)viewDidLoad
{
 NSString *path = [[NSBundle mainBundle] pathForResource:@"BackgroundSound" ofType:@"mp3"];
    play =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    play.delegate=self;
    [play play];
}

および PlayAreaView:

- (void)counttimer
{
    ///here is my code for NSTimer, if Timer is 0, Automatically I go to GameOver viewController
    MainMenuView *vv = [[MainMenu alloc]init];
    [vv.play stop];
    GameOver *gv = [[GameOver alloc]init];
    [self presentViewController:gv animated:YES completion:nil];
}

GameOver に移動する前、または既にゲーム オーバー ビューになっているときにAVAudioPlayerMainMenuView. 助けてください。MainMenuViewを割り当てて使用しようとしまし[MainMenu.play stop]たが、うまくいきません。

4

1 に答える 1

0

まず、変数に少し異なる名前を付ける必要があります。コードで"" を見る[play play]のは本当に奇妙です。

第 2 に、あなたの " counttimer" メソッドを見ると、 " " & " "MainMenuViewを介して " " ビュー コントローラーを作成し、ビューが読み込まれる前でもすぐにプレーヤーを停止していることがわかります。allocinit

プレーヤーを停止したい場合は、" AVAudioPlayer" オブジェクトが実際にロードされていることを確認してください。

したがって、コードで次のようにします。

if (vv.play)
    [vv.play stop];
else
    NSLog( @"vv.play is NULL, it doesn't exist yet");

これは、" " を呼び出すのに適切な場所を追跡するのに役立ちますstop

于 2012-11-24T14:49:49.193 に答える