As far as I know, there is not native or third party library available to play MIDI on the iPhone. But there seem to be quite a few apps that do exactly that. What are they using? Any clues?
Asked
Active
Viewed 1.8k times
10
-
1If there are no third party libaraies for playing MIDI, they probably just made their own, or looked harded... or paid. MIDI should be a fairly simple format to work out what's going on, then you just need to play modulate your samples to play them like the song requested. Remember, MIDI dose not say what it HAS to sound like, only what it should play. It's up to your MIDI software/hardware to turn it into anything good. – thecoshman Mar 31 '10 at 09:02
-
1MIDI is natively supported in iOS, just link with the CoreMIDI framework. – Berik Mar 25 '13 at 09:20
-
I've written a tutorial on how to play MIDI using CoreMIDI through an AUGraph here. – James Andrews Mar 22 '12 at 21:21
-
I found this library that is available for licensing. Hope it helps someone else. http://www.crimsontech.jp/eng/softsynth/ – Plumenator Apr 21 '10 at 08:43
3 Answers
6
FYI for those going down this road: AVMIDIPlayer was introduced in iOS 8. Seems to work well on device, sim not so much.

Phil Loden
- 1,394
- 1
- 15
- 15
-
This is the way to go. For a tutorial, check this out: http://www.rockhoppertech.com/blog/swift-and-avmidiplayer/ – Zeezer Sep 02 '15 at 19:59
2
This worked for me for playing midi file on iPhone:
import AVFoundation
class MidiPlayer: NSObject {
static let shared = MidiPlayer()
var musicPlayer: MusicPlayer?
var sequence: MusicSequence?
func play(file: String) {
guard let midiFile = Bundle.main.url(forResource: file, withExtension: "mid") else {
return
}
NewMusicPlayer(&musicPlayer)
NewMusicSequence(&sequence)
if let musicPlayer = musicPlayer, let sequence = sequence {
MusicSequenceFileLoad(sequence, midiFile as CFURL, .midiType, MusicSequenceLoadFlags())
MusicPlayerSetSequence(musicPlayer, sequence)
MusicPlayerStart(musicPlayer)
}
}
func stop() {
if let musicPlayer = musicPlayer {
MusicPlayerStop(musicPlayer)
}
}
}
and then MidiPlayer.shared.play(file: "midifile")

Leszek Szary
- 9,763
- 4
- 55
- 62
1
Check out the MusicPlayer class. Combined with the AUSampler audio unit available since iOS 5.0 you can build a MIDI player quite easily. (The link is OS X, but it applies for iOS as well)
About the sampler audio unit see: Simple embeddable MidiSynth for iOS?

Community
- 1
- 1

lukebuehler
- 4,061
- 2
- 24
- 28