Contents

play(atTime:)

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

Declaration

func play(atTime time: TimeInterval) -> Bool

Parameters

  • time:

    The audio device time to begin playback. This time must be later than the device’s current time.

Return Value

true if playback starts successfully; otherwise, false.

Discussion

Use this method to precisely synchronize the playback of two or more audio player objects as the following example shows:

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)
}

Calling this method implicitly calls prepareToPlay() if the audio player is unprepared for playback.

See Also

Controlling playback