-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];
}
我什麼也看不到你的代碼明顯錯誤,你會得到任何警告,錯誤等?你確定聲音文件源的URL構造正確嗎? –
[Cocoa audio issues]可能的重複(http://stackoverflow.com/questions/7231346/cocoa-audio-issues) – coneybeare
如果你想得到任何答案,我建議你閱讀http://stackoverflow.com/faq 。重複的問題將被關閉 – coneybeare