【问题标题】:Play multiple audio at one same time同时播放多个音频
【发布时间】:2013-12-11 07:49:32
【问题描述】:

我的客户想要创建一个应用程序,用户可以在其中一次播放 4 个音频,然后开始启动任何音频,然后将它们记录为一个文件。

我没有开发过音频/视频应用程序,所以我想知道这在 ios sdk 中是否可行?

可以同时播放多少个音频文件?

【问题讨论】:

  • 这取决于您使用的 API。有许多。 OpenAL、MediaPlayer、CoreAudio、...

标签: ios iphone objective-c audio avfoundation


【解决方案1】:

您可以使用AVAudioSession同时播放多首音乐。

UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);

【讨论】:

  • 那么,就是说我们可以同时播放4个音频,然后录制4个音频,把它变成一个对吗?
  • 我从来没有做过任何录音(但我相信你会在文档中找到这个:)),但我用它来同时播放不同的音轨。跨度>
【解决方案2】:

您可以使用此代码播放多个音频文件

NSString *songA = [[NSBundle mainBundle] pathForResource:@"songA" ofType:@"mp3"];
NSError *soundError = nil;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:songA] error:&soundError];
if(self.player == nil)
    NSLog(@"%@",soundError);
else
{
    [self.player setDelegate:self];
    [self.player setVolume:0.75];
    [self.player play];
}

NSString *songB = [[NSBundle mainBundle] pathForResource:@"songB" ofType:@"mp3"];
soundError = nil;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:songB] error:&soundError];
if(self.player == nil)
    NSLog(@"%@",soundError);
else
{
    [self.player setDelegate:self];
    [self.player setVolume:0.25];
    [self.player play];
}

要合并多个音频文件,您可以使用此问题的答案Combining two .caf files on iPhone

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多