<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioSequencer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioSequencer"
  },
  "title" : "AVAudioSequencer"
}
-->

# AVAudioSequencer

An object that plays audio from a collection of MIDI events the system organizes into music tracks.

```
class AVAudioSequencer
```

## Topics

### Creating an Audio Sequencer

[`-  init`](/documentation/AVFAudio/AVAudioSequencer/init())

Creates an audio sequencer object.

[`-  initWithAudioEngine:`](/documentation/AVFAudio/AVAudioSequencer/init(audioEngine:))

Creates an audio sequencer that the framework attaches to an audio engine instance.

### Writing to a MIDI File

[`-  writeToURL:SMPTEResolution:replaceExisting:error:`](/documentation/AVFAudio/AVAudioSequencer/write(to:smpteResolution:replaceExisting:))

Creates and writes a MIDI file from the events in the sequence.

### Handling Music Tracks

[`AVMusicTrack`](/documentation/AVFAudio/AVMusicTrack)

A collection of music events that you can offset, set to a muted state, modify independently from other track events, and send to a specified destination.

[`-  createAndAppendTrack`](/documentation/AVFAudio/AVAudioSequencer/createAndAppendTrack())

Creates a new music track and appends it to the sequencer’s list.

[`-  reverseEvents`](/documentation/AVFAudio/AVAudioSequencer/reverseEvents())

Reverses the order of all events in all music tracks, including the tempo track.

[`-  removeTrack:`](/documentation/AVFAudio/AVAudioSequencer/removeTrack(_:))

Removes the music track from the sequencer.

[`AVMusicTrackLoopCount`](/documentation/AVFAudio/AVMusicTrackLoopCount)

Options that define the number of times a track loops.

### Handling Music Events

[`AVMusicEvent`](/documentation/AVFAudio/AVMusicEvent)

A base class for the events you associate with a music track.

[`AVMusicUserEvent`](/documentation/AVFAudio/AVMusicUserEvent)

An object that represents a custom user message.

[`AVParameterEvent`](/documentation/AVFAudio/AVParameterEvent)

An object that represents a parameter event on a music track’s destination.

[`AVAUPresetEvent`](/documentation/AVFAudio/AVAUPresetEvent)

An object that represents a preset load and change on the music track’s destination audio unit.

[`AVExtendedTempoEvent`](/documentation/AVFAudio/AVExtendedTempoEvent)

An object that represents a tempo change to a specific beats-per-minute value.

[`AVExtendedNoteOnEvent`](/documentation/AVFAudio/AVExtendedNoteOnEvent)

An object that represents a custom extension of a MIDI note on event.

### Handling MIDI Events

[`AVMIDINoteEvent`](/documentation/AVFAudio/AVMIDINoteEvent)

An object that represents MIDI note on or off messages.

[`AVMIDIMetaEvent`](/documentation/AVFAudio/AVMIDIMetaEvent)

An object that represents MIDI meta event messages.

[`AVMIDISysexEvent`](/documentation/AVFAudio/AVMIDISysexEvent)

An object that represents a MIDI system exclusive message.

### Handling MIDI Channel Events

[`AVMIDIChannelEvent`](/documentation/AVFAudio/AVMIDIChannelEvent)

A base class for all MIDI messages that operate on a single MIDI channel.

[`AVMIDIChannelPressureEvent`](/documentation/AVFAudio/AVMIDIChannelPressureEvent)

An object that represents a MIDI channel pressure message.

[`AVMIDIProgramChangeEvent`](/documentation/AVFAudio/AVMIDIProgramChangeEvent)

An object that represents a MIDI program or patch change message.

[`AVMIDIPolyPressureEvent`](/documentation/AVFAudio/AVMIDIPolyPressureEvent)

An object that represents a MIDI poly or key pressure event.

[`AVMIDIPitchBendEvent`](/documentation/AVFAudio/AVMIDIPitchBendEvent)

An object that represents a MIDI pitch bend message.

[`AVMIDIControlChangeEvent`](/documentation/AVFAudio/AVMIDIControlChangeEvent)

An object that represents a MIDI control change message.

### Managing Sequence Load Options

[`-  loadFromData:options:error:`](/documentation/AVFAudio/AVAudioSequencer/load(from:options:)-8o58w)

Parses the data and adds its events to the sequence.

[`-  loadFromURL:options:error:`](/documentation/AVFAudio/AVAudioSequencer/load(from:options:)-9kb6m)

Loads the file the URL references and adds the events to the sequence.

[`AVMusicSequenceLoadOptions`](/documentation/AVFAudio/AVMusicSequenceLoadOptions)

A structure that defines whether data on different MIDI channels map to multiple tracks, or whether the framework preserves the tracks as they are.

### Operating an Audio Sequencer

[`-  prepareToPlay`](/documentation/AVFAudio/AVAudioSequencer/prepareToPlay())

Gets ready to play the sequence by prerolling all events.

[`-  startAndReturnError:`](/documentation/AVFAudio/AVAudioSequencer/start())

Starts the sequencer’s player.

[`-  stop`](/documentation/AVFAudio/AVAudioSequencer/stop())

Stops the sequencer’s player.

### Managing Time Stamps

[`AVMusicTimeStamp`](/documentation/AVFAudio/AVMusicTimeStamp)

A fractional number of beats.

[`-  hostTimeForBeats:error:`](/documentation/AVFAudio/AVAudioSequencer/hostTime(forBeats:error:))

Gets the host time the sequence plays at the specified position.

[`-  secondsForBeats:`](/documentation/AVFAudio/AVAudioSequencer/seconds(forBeats:))

Gets the time for the specified beat position (timestamp) in the track, in seconds.

### Handling Beat Range

[`-  beatsForHostTime:error:`](/documentation/AVFAudio/AVAudioSequencer/beats(forHostTime:error:))

Gets the beat the system plays at the specified host time.

[`-  beatsForSeconds:`](/documentation/AVFAudio/AVAudioSequencer/beats(forSeconds:))

Gets the beat position (timestamp) for the specified time in the track.

[`AVMusicTimeStampEndOfTrack`](/documentation/AVFAudio/AVMusicTimeStampEndOfTrack)

A timestamp you use to access all events in a music track through a beat range.

[`AVBeatRange`](/documentation/AVFAudio/AVBeatRange-swift.typealias)

[`AVBeatRange`](/documentation/AVFAudio/AVBeatRange-c.struct)

A specific time range within a music track.

### Setting the User Callback

[`-  setUserCallback:`](/documentation/AVFAudio/AVAudioSequencer/setUserCallback(_:))

Adds a callback that the sequencer calls each time it encounters a user event during playback.

[`AVAudioSequencerUserCallback`](/documentation/AVFAudio/AVAudioSequencerUserCallback)

A callback the sequencer calls asynchronously during playback when it encounters a user event.

### Getting Sequence Properties

[`playing`](/documentation/AVFAudio/AVAudioSequencer/isPlaying)

A Boolean value that indicates whether the sequencer’s player is in a playing state.

[`rate`](/documentation/AVFAudio/AVAudioSequencer/rate)

The playback rate of the sequencer’s player.

[`tracks`](/documentation/AVFAudio/AVAudioSequencer/tracks)

An array that contains all the tracks in the sequence.

[`currentPositionInBeats`](/documentation/AVFAudio/AVAudioSequencer/currentPositionInBeats)

The current playback position, in beats.

[`currentPositionInSeconds`](/documentation/AVFAudio/AVAudioSequencer/currentPositionInSeconds)

The current playback position, in seconds.

[`tempoTrack`](/documentation/AVFAudio/AVAudioSequencer/tempoTrack)

The track that contains tempo information about the sequence.

[`userInfo`](/documentation/AVFAudio/AVAudioSequencer/userInfo)

A dictionary that contains metadata from a sequence.

[`InfoDictionaryKey`](/documentation/AVFAudio/AVAudioSequencer/InfoDictionaryKey)

Constants that defines metadata keys for a sequencer.

[`-  dataWithSMPTEResolution:error:`](/documentation/AVFAudio/AVAudioSequencer/data(withSMPTEResolution:error:))

Gets a data object that contains the events from the sequence.

[`AVMusicTimeStampEndOfTrack`](/documentation/AVFAudio/AVMusicTimeStampEndOfTrack)

A timestamp you use to access all events in a music track through a beat range.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)