Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

AVAudioPlayerNodeMBS class

Super class: AVAudioNodeMBS

Type Topic Plugin Version macOS Windows Linux Console & Web iOS
class AVFoundationNode MBS AVFoundation Plugin 15.3 Yes No No Yes, macOS only No
Function: The AVAudioPlayerNode class plays buffers or segments of audio files.
AVAudioPlayerNode supports scheduling the playback of AVAudioBuffer instances, or segments of audio files opened via AVAudioFile. 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 AVAudioMixerNode 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.

This class overrides the AVAudioNode method reset and unschedules all previously scheduled buffers and file segments, and also returns the player timeline to sample time 0.

Player Timeline
The usual AVAudioNode sample times (as observed by lastRenderTime ) have an arbitrary zero point. AVAudioPlayerNode 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 nodeTimeForPlayerTime and playerTimeForNodeTime convert between the two.

Scheduling Playback Time
The scheduleBuffer, scheduleFile, and scheduleSegment methods take an AVAudioTime when parameter. This is interpreted as follows:

  • If the when parameter is nil:
    • 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 0.
  • If the when parameter is a sample time, the parameter is interpreted as such.
  • If the when parameter 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.
  • An AVAudioTime specifies neither a valid sample time or host time.
  • A segment's start frame or frame count is negative.
Subclass of the AVAudioNodeMBS class.

Feedback, Comments & Corrections

Options controlling buffer scheduling

Constant Value Description
BufferInterrupts 2 The buffer interrupts any buffer already playing.
BufferInterruptsAtLoop 4 The buffer interrupts any buffer already playing, at its loop point.
BufferLoops 1 The buffer loops indefinitely.

Completion Handler Modes

Constant Value Description
CompletionDataConsumed 0 The buffer or file data has been consumed by the player.
CompletionDataPlayedBack 2 Applicable only when the engine is rendering to/from an audio device.
The buffer or file has finished playing. This accounts for both (small) signal processing latencies downstream of the player in the engine, as well as (possibly significant) latency in the audio playback device.
CompletionDataRendered 1 The buffer or file data has been rendered (i.e. output) by the player. This does not account for any signal processing latencies downstream of the player in the engine (see AVAudioNodeMBS.outputPresentationLatency).

Super class AVAudioNodeMBS

This class has no sub classes.

Some examples which use this class:

Blog Entries

The items on this page are in the following plugins: MBS AVFoundation Plugin.

AVAudioPlayerMBS   -   AVAudioRecorderMBS

MBS FileMaker blog