2011-10-02 2 views
0

그래서 저는 거의 내 응용 프로그램을 다 끝내고 벽을 치고이 마지막 문제를 해결할 수 없습니다.AVAudioPlayer 알림 문제

기본적으로 2 개의보기가 있습니다. 메인 페이지와 게임 플레이 화면.

처음에는 게임이 정상적으로 작동하지만 메인 화면을 종료하고 게임 화면으로 돌아 가면 모든 사운드가 복제되고 playerItemDidReachEnd가 일찍 발생합니다 (왜냐하면 2 개의 인스턴스가 있다고 생각하기 때문입니다). ,하지만 그것을 막을 수 없어 플레이어를 막을 수 없습니다.이 기본 코드를 일으키는 것입니다. 어떤 도움이 먼 길을 갈 것입니다, 감사합니다. 내 문제는 내가 View1 View2의 여러 인스턴스를 만드는 경우 잘 모르겠습니다. 또는 view2에 여러 플레이어 개체를 만들어서 알림을 복제하는 경우 내 - (void) playerItemDidReachEnd : (NSNotification *) 알림에 많은 문제가 있음을 알고 있지만 페이지의 첫 번째로드에서는 정상적으로 작동합니다. , "view1로 돌아 가기"를 클릭 한 다음 View2로 돌아가서 문제가 발생하는 경우에만 해당

View1ViewController.h 
---------------------- 
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h> 
#import "ApplicationViewController.h" 

@interface MonsterSpellViewController : UIViewController { 
} 
-(IBAction)showView1; 

View2ViewController.m 
---------------------- 
-(IBAction)showView2{ 

    ApplicationViewController *view2 = [[ApplicationViewController alloc]initWithNibName:@"ApplicationViewController" bundle:nil]; 

    view2.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:view2 animated:YES]; 

} 



View2ViewController.h 
------------------------ 
#import "(i know here are arrows here, but can't make them show)UIKit/UIKit.h> 
#import "(i know here are arrows here, but can't make them show)AVFoundation/AVFoundation.h> 

@class AVAudioPlayer; 

@interface ApplicationViewController : UIViewController{ 

AVAudioPlayer *avPlayer; 
} 

View2ViewController.m 
------------------------- 
#import "View2ViewController.h" 

@synthesize avPlayer; 

-(AVAudioPlayer *)avPlayer { 
    if(!avPlayer) avPlayer = [[AVAudioPlayer alloc]init]; 
    return avPlayer; 
} 

-(void) viewDidLoad 
{ 

[[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(playerItemDidReachEnd:) 
    name:AVPlayerItemDidPlayToEndTimeNotification 
    object:avPlayer]; 
} 

-(IBAction)playSoundTest 
{ 
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/monster3.mp3", [[NSBundle mainBundle] resourcePath]]]; 

    self.avPlayer = [AVPlayer playerWithURL:url]; 

    [self.avPlayer play]; 
} 

- (void)playerItemDidReachEnd:(NSNotification *)notification { 
    //[player seekToTime:kCMTimeZero]; 
    if (playEscape == YES) { 
     [self btnEscapeSound]; 
     playEscape = NO; 
    } 
    if ((startButton.hidden == NO) && (letterCount != -1) && (playFinal == YES)) 
    { 
     [self btnFinalSound]; 
     playFinal = NO; 
     playEscape = YES; 
    } 

    NSLog(@"Player Check accessed"); 
    if (letterCount == 3) { 

     if (Winner == letterCount) { 
      //moveNextSound = YES; 
      if (intLoopCount < 104) 
      { 
       if (intLoopCount<104) { 


        [self btnStartOver:intLoopCount]; 
        playFinal = NO; 
        //intLoopCount++; 
       } 
       if (intLoopCount==104) { 
        startButton.hidden=NO; 
        playFinal = YES; 

       } 
      } 
     } 
    } 

    if (letterCount == 4) { 

     if (Winner == letterCount) { 
      //moveNextSound = YES; 
      if (intLoopCount < 105) 
      { 
       [self btnStartOver:intLoopCount]; 
       //intLoopCount++; 
       if (intLoopCount==105) { 
        startButton.hidden=NO; 
        playFinal = YES; 
       } 
      } 
     } 
    } 





} 
} 

-(IBAction)goBack:(id)sender{ 


    [self dismissModalViewControllerAnimated:YES]; 

} 

답변

0

[view2 release]를 추가해보세요. after [self presentModalViewController : view2 animated : YES];