我有两个视图控制器:
主菜单视图:
- (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 之前,或者当我已经在游戏概览中时,我想停止AVAudioPlayer
我的MainMenuView
. 请帮忙。我尝试分配MainMenuView
和使用[MainMenu.play stop]
,但不起作用。