2012-07-18 106 views
0

當視圖打開時,我有背景音樂,即使我將視圖切換到其他視圖並返回到主視圖,背景音樂仍在播放問題。但是當我後退按鈕從dismissModalViewControllerAnimated關閉我的背景音樂

mainViewController *mainView =[[mainViewController alloc] initWithNibName:nil bundle:nil]; 
mainView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:mainView animated:YES]; // this will flip from right 

當翻轉回主菜單中更改我的代碼

[self dismissModalViewControllerAnimated:YES]; // this will flip back from left 

,我的背景音樂是​​不是在玩。只是好奇爲什麼?如何解決它?出於某種原因,我將代碼更改爲[self dismissModalViewControllerAnimated:YES];因爲我希望我的觀點從其他方面反轉回來。當MAINVIEW是使用此代碼

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     NSString *pathFile = [[NSBundle mainBundle] pathForResource:@"Start" ofType:@"mp3"]; 
     player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathFile] error:NULL]; 
     [player play]; 
    } 

停止,如果觀點是改變

- (void) viewDidDisappear:(BOOL)animated 
{ 
    [player stop]; 
} 

回答

0

開始你ViewDidApper方法播放節目

我的背景音樂播放。希望它會幫助你

-(void)viewDidAppear:(BOOL)animated 
{ 
NSString *pathFile = [[NSBundle mainBundle] pathForResource:@"Start" ofType:@"mp3"]; 
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathFile] error:NULL]; 
    [player play]; 
[super viewDidAppear:YES]; 
} 
+0

我以前試過,結果是一樣的。不會玩。只是好奇爲什麼? – SyntaxError 2012-07-18 12:51:57