在iphone中同时有2个mp3声音? [英] 2 mp3 sounds at the same time in iphone?

查看:178
本文介绍了在iphone中同时有2个mp3声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在iphone上同时播放2个mp3声音吗?iphone是否支持此功能?

Can we play 2 mp3 sounds on the same time on the iphone?Does iphone support this feature?

推荐答案

使用音频队列服务(AudioToolbox / AudioQueue.h)中的接口。为要播放的每个声音创建一个音频队列对象。然后使用AudioQueueEnqueueBufferWithParameters函数指定每个音频队列中第一个音频缓冲区的同时开始时间。

Use the interfaces in Audio Queue Services (AudioToolbox/AudioQueue.h). Create one audio queue object for each sound that you want to play. Then specify simultaneous start times for the first audio buffer in each audio queue, using the AudioQueueEnqueueBufferWithParameters function.

以下限制适用于iPhone OS中的同步声音,具体取决于音频数据格式:

The following limitations pertain for simultaneous sounds in iPhone OS, depending on the audio data format:

AAC,MP3和ALAC(Apple Lossless)音频:您可以同时播放多种AAC,MP3和ALAC格式的声音;播放这些格式的多个声音将需要CPU资源进行解码。

AAC, MP3, and ALAC (Apple Lossless) audio: You may play multiple AAC, MP3, and ALAC format sounds simultaneously; playback of multiple sounds of these formats will require CPU resources for decoding.

线性PCM和IMA / ADPCM(IMA4音频):您可以播放多个线性PCM或IMA4格式的声音同时没有CPU资源问题。

Linear PCM and IMA/ADPCM (IMA4 audio): You can play multiple linear PCM or IMA4 format sounds simultaneously without CPU resource concerns.

在一次播放多个声音方面,这很容易,只需为你想玩的每一个创建一个新的播放器实例(并记住)在你完成时释放它们)

In terms of playing multiple sounds at once, that's easy, just create a new player instance for every one that you want to play (and remember to release them when you're done)

 NSString *path = [[NSBundle mainBundle] pathForResource:@"YOUR_FILE_NAME" ofType:@"m4a"];  
 AVAudioPlayer* objAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
 objAudio.delegate = self;  
 [objAudio play];

要将MP3转换为IMA4(您可以同时播放多个),您可以运行以下(在终端,豹子):

To convert an MP3 into something like IMA4 (which you can play more than one at once) you would run the following (in terminal, in leopard):

 /usr/bin/afconvert -f caff -d ima4 sound.mp3 sound.caf

更多信息,请访问音频播放/录制

这篇关于在iphone中同时有2个mp3声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆