AVAudio class plays buffers or segments of audio files.
- iOS 8.0+
- macOS 10.10+
- tvOS 9.0+
- watchOS 2.0+
AVAudio supports scheduling the playback of
AVAudio instances, or segments of audio files opened via
AVAudio. Buffers and segments may be scheduled at specific points in time, or to play immediately following preceding segments.
Normally, you will want to configure the node’s output format with the same number of channels as are in the files and buffers to be played. Otherwise, channels will be dropped or added as required. It is usually better to use an
AVAudio to do this.
Similarly, when playing file segments, the node will sample rate convert if necessary, but it is often preferable to configure the node’s output sample rate to match that of the file(s) and use a mixer to perform the rate conversion.
When playing buffers, there is an implicit assumption that the buffers are at the same sample rate as the node’s output format.
AVAudio sample times (as observed by
last ) have an arbitrary zero point.
AVAudio superimposes a second “player timeline” on top of this, to reflect when the player was started, and intervals during which it was paused. The methods
player convert between the two.
Scheduling Playback Time
schedulemethods take an
when parameter. This is interpreted as follows:
If there have been previous commands, the new one is played immediately following the last one.
Otherwise, if the node is playing, the event is played in the very near future.
Otherwise, the command is played at sample time
whenparameter is a sample time, the parameter is interpreted as such.
whenparameter is a host time it is ignored unless sample time not valid.
The scheduling methods will fail if:
A buffer's channel count does not match that of the node's output format.
A file can't be accessed.
AVAudiospecifies neither a valid sample time or host time.
A segment's start frame or frame count is negative.