2011-08-29 13 views
-3

こんにちは私は次のページに私を連れて行くには、次のボタンをクリックすると、ページのターン音を再生しようとしているが、私は "再生"ボタンを押すと音楽が再生され、誰でもここで助けてください。難易度オーディオファイル

- (IBAction)next { 

    // This part plays the next page turn noise 
    NSURL *this = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/next.mp3", [[NSBundle mainBundle] resourcePath]]]; 

    NSError *error; 
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:this error:&error]; 
    [audioPlayer setDelegate:self]; 
    audioPlayer.numberOfLoops = 0; 
    [audioPlayer play]; 

    // This part takes us to the next view 
    Rabbana2 *rab = [[Rabbana2 alloc] initWithNibName:@"Rabbana2" bundle:nil]; 
    [UIView beginAnimations:@"flipView" context:Nil]; 
    [UIView setAnimationDuration:2]; 
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 

    [self.view addSubview:rab.view]; 
    [UIView commitAnimations]; 

} 

// This button plays the audio 
- (IBAction)play { 

    if(clicked == 0){ 
     clicked = 1; 
     NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/rabbana1.wav", [[NSBundle mainBundle] resourcePath]]]; 

     NSError *error; 
     audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
     [audioPlayer setDelegate:self]; 
     audioPlayer.numberOfLoops = 0; 


     [audioPlayer play]; 
     [start setImage:[UIImage imageNamed:@"Sstop.png"] forState:UIControlStateNormal]; 

    } 
    else{ 
     [audioPlayer release]; 
     clicked = 0; 
     [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal]; 
    } 

} 

//If user does not do anything by the end of the sound set the button to start 
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) flag { 
    if (flag==YES) { 
     clicked = 0; 
     [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal]; 
    } 
+1

out.caf私は何も見ませんあなたのコードにうっかり間違っている、あなたはどんな警告やエラーなども受け取りますか?サウンドファイルのソースのURLが正しく構築されていますか? –

+0

[Cocoa audio issues]の複製が可能です(0120-998-504) – coneybeare

+1

回答を得たい場合はhttp://stackoverflow.com/faqを読むことをお勧めします。重複した質問が閉じられる – coneybeare

答えて

0

私はあなたのオーディオファイルが正しくエンコードされていることを確認します: は、ここでは、コードです。あなたのコードが再生を実行している可能性がありますが、オーディオファイルが不適切にエンコードされているため再生できません。ここで

は(愛をされたiPhoneた)CAFにwavファイルを変換するためのコマンドライン変換である

afconvert -f CAFF -d LEI16 44100 -c 1 @ in.wav

+1

彼が問題を抱えている「次の」サウンドは.mp3だと思われますが、その変換はどうなっているのでしょうか? –