-4
我設法創建了包含動畫的應用程序。但是我想通過添加一個從網絡上下載的.wav文件使其脫穎而出,更加有趣。我希望聲音在動畫期間播放。纔開始編碼一個月前,所以任何幫助,將深表讚賞如何在我在xcode中創建的動畫中播放聲音?
我設法創建了包含動畫的應用程序。但是我想通過添加一個從網絡上下載的.wav文件使其脫穎而出,更加有趣。我希望聲音在動畫期間播放。纔開始編碼一個月前,所以任何幫助,將深表讚賞如何在我在xcode中創建的動畫中播放聲音?
您可以使用AVAudioPlayer
只需創建一個方法,並將其連接到您的按鈕或動畫
-(void) playLoopingMusicInApplication {
AVAudioPlayer *audioPlayer;
// set the pathForResource: to the name of the sound file, and ofType: to AAC preferrably.
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"WAV"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.delegate = self;
//infinite
player.numberOfLoops = -1;
[player play];
//[player release];
}
希望這有助於!
這非常棒。請問另一個問題:如何創建一個方法將其連接到我的動畫? –
請向我們展示代碼示例以及您嘗試過的任何迄今尚未運行的代碼示例。 –