-4

我设法创建了这个包含动画的应用程序。但是我想通过添加一个我从网上下载的 .wav 文件来让它脱颖而出并更有趣。我希望声音在动画期间播放。一个月前才开始编码,所以任何帮助都将不胜感激

4

1 回答 1

0

你可以使用 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];
}
  • PS - 您需要在项目中获取 AVFoundation 框架和 AudioToolbox 框架

希望这可以帮助!

于 2013-07-23T02:26:46.560 回答