Class

Sound

All views that contain shapes are exported from Flow as `ShapeView` objects.


Declaration

class Sound

Overview

A Sound object takes in a audio player and triggers playback after a specific TimeInterval.

Topics

Playback

playAudio(…)

A static method that accepts an AVAudioPlayer and a TimeInterval in order to initiate playback of an audio file.

static func playAudio(_ audio: AVAudioPlayer, delay: TimeInterval) {
    audio.prepareToPlay()
    let time = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
    DispatchQueue.main.asyncAfter(deadline: time) {
        audio.play()
    }
}

For example, the following will play the audio file associated with myPlayer after a delay of 1s.

Sound.playAudio(myPlayer, delay: 1.0)
background Made with Flow.
underscore Made with Flow.
line2 Made with Flow.
line1 Made with Flow.
circle Made with Flow.
hit Made with Flow.

result(s) found for “”.