Ignacio Ocampo
Ignacio Ocampo

Reputation: 2713

Play midi file or midi tone in iPhone with Xcode / Cocoa

I need to play midi file or midi tone in iPhone.

I have tested MidiMonitor. I think that I need to create a destination point on the iPhone to receive midi, but I don't know how do it.

Can you help me? Example source code would be useful.

Upvotes: 3

Views: 4083

Answers (2)

Berik
Berik

Reputation: 8143

Like @skinnyTOD noted, from iOS 5.0 on it is possible to use MediaPlayer. First link the AVFoundation, and AudioToolbox frameworks to your project, then use this code:

#import <AVFoundation/AVFoundation.h>

NSURL *midiUrl = [[NSBundle mainBundle] URLForResource:@"even voor mij" withExtension:@"mid"];
MusicPlayer player = NULL;
NewMusicPlayer(&player);
MusicSequence sequence = NULL;
NewMusicSequence(&sequence);
MusicSequenceFileLoad(sequence, (__bridge CFURLRef)midiUrl, NULL, NULL);
MusicPlayerSetSequence(player, sequence);
MusicPlayerStart(player);

This sets up the player with your midi file from bundle, and start playing. Note that you will need to call DisposeMusicSequence and DisposeMusicPlayer when cleaning up the player.

Upvotes: 3

spring
spring

Reputation: 18517

If you are still trying to sort this, iOS 5 includes the MusicPlayer API - it can load, play and create midi files. You'll need to also read up on the new AUSampler AudioUnit.

Upvotes: 2

Related Questions