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

# AVMIDIPlayer

An object that plays MIDI data through a system sound module.

```
class AVMIDIPlayer
```

## Overview

For more information about preparing your app to play audio, see <doc://com.apple.documentation/documentation/AVFoundation/configuring-your-app-for-media-playback>.

> Important:
> For more advanced MIDI playback capabilities, like playing MIDI data through an external synthesizer or sampler, use ``doc://com.apple.avfaudio/documentation/AVFAudio/AVAudioEngine`` instead.

## Topics

### Creating a MIDI player

[`init(contentsOf:soundBankURL:)`](/documentation/AVFAudio/AVMIDIPlayer/init(contentsOf:soundBankURL:))

Creates a player to play a MIDI file with the specified soundbank.

[`init(data:soundBankURL:)`](/documentation/AVFAudio/AVMIDIPlayer/init(data:soundBankURL:))

Creates a player to play MIDI data with the specified soundbank.

### Controlling playback

[`prepareToPlay()`](/documentation/AVFAudio/AVMIDIPlayer/prepareToPlay())

Prepares the player to play the sequence by prerolling all events.

[`play(_:)`](/documentation/AVFAudio/AVMIDIPlayer/play(_:))

Plays the MIDI sequence.

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

A callback the system invokes when MIDI playback completes.

[`stop()`](/documentation/AVFAudio/AVMIDIPlayer/stop())

Stops playing the sequence.

[`isPlaying`](/documentation/AVFAudio/AVMIDIPlayer/isPlaying)

A Boolean value that indicates whether the sequence is playing.

### Configuring playback settings

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

The playback rate of the player.

### Accessing player timing

[`currentPosition`](/documentation/AVFAudio/AVMIDIPlayer/currentPosition)

The current playback position, in seconds.

[`duration`](/documentation/AVFAudio/AVMIDIPlayer/duration)

The duration, in seconds, of the currently loaded file.



---

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)