2 mp3 sounds at the same time in iphone?

前端 未结 2 795
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 04:24

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

2条回答
  •  生来不讨喜
    2020-12-20 04:48

    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.

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

    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.

    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];
    

    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
    

    for More information, visit Audio Play/Record

提交回复
热议问题