1

There is an example here on using AVAudioPlayer. In the description it says it's able to:

  • Play multiple sounds at the same time with optional synchronization.

I don't see how to do that in the example.

Apple API that says the same thing:

  • Play multiple sounds simultaneously by synchronizing the playback of multiple players

https://developer.apple.com/documentation/avfaudio/avaudioplayer?language=objc

Example:
https://github.com/xamarin/docs-archive/tree/master/Recipes/ios/media/sound/avaudioplayer

Note: The repository is archived and does not allow adding issues.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231

1 Answers1

0

Use the playAtTime() method on all the sounds you want and pass in the same date to all the sounds to play at the same time.

I read about the playAtTime() method and thought it was "play at this position in time of the sound" BECAUSE IT SAYS IT SAYS THE PARAMETER IS NAMED TIME NOT DATE:

enter image description here

but it actually takes a Date and that means play at a future date and time.

So if you were only looking at the auto complete API and it says playAtTime(time) you don't get the details you do when looking at the documentation. Seeing that there is another property on sound player that is currentTime that is a number and not a date.

enter image description here

Documentation:

Plays audio asynchronously, starting at a specified point in the audio output device’s timeline.

func startSynchronizedPlayback() {
    // Create a time offset relative to the current device time.
    let timeOffset = playerOne.deviceCurrentTime + 0.01
    
    // Start playback of both players at the same time.
    playerOne.play(atTime: timeOffset)
    playerTwo.play(atTime: timeOffset)
}
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231