An extension for playing MIDI files. This is currently in alpha; please see below for a list of features and bugs. The function names are currently intended to match that of Apple’s AVMIDIPlayer; however, this is subject to change upon release.
Init(contentsOf, soundBankURL): Initializes the component with the contents of the MIDI file specified by the path, using the specified sound bank (SF2). This MUST be called before doing anything else, and to change the loaded MIDI or sound bank file. File paths can be used in the same way as the ReadFrom method of the File component (docs).
Play(): Plays the sequence.
Stop(): Stops playing the sequence.
Events
Completed(): A block to be called when a MIDI playback request is completed. This currently is never called.Fixed.
Properties
boolean IsPlaying()get: A Boolean value that indicates whether the sequence is playing.
long Duration()get: The length of the currently loaded file, in seconds.
long CurrentPosition()get set: The current playback position, in seconds.
float Rate()get set: The playback rate of the player.
Known Issues
You cannot currently access packaged assets (a path starting with two slashes will throw an UnsupportedOperationException, since I haven’t implemented this yet). One workaround is to use the Web component to download the files you need to external storage or to the private user data directory and access them from there.Fixed.
Friendly error handling is buggy right now - please use adb logcat
Downloads
Alpha 3
AIX: (coming soon)
Example AIA
AIA: (will return soon)
Feel free to reply with any feedback, questions, comments, and/or concerns you may have.
It looks like there is a bug in the library I’m using*, which is why you aren’t hearing audio. I thought the change I made would fix this, but no (it didn’t work on the emulator, but I figured that it would work on real hardware). Will need to investigate further and see what I can do.