Wednesday, 16 January 2013

Playing MIDI Files


Playing MIDI Files

Even though MP3 files are abundant nowadays, the MP3 format is not
suitable for every purpose. To demonstrate how to play other sound
formats besides MP3, Example 25 uses a Musical Instrument Digital
Interface (MIDI) file.
As the name suggests, a MIDI file contains commands that musical
instruments transmit to control various attributes of music, such as playing
notes and adjusting an instrument’s sound in various ways.
Playing MIDI files works in exactly the same way as playing MP3 files.
As in the previous example, your sound file should be placed on your
memory card.


Example 25: MIDI player
import audio
midi = audio.Sound.open("E:\\Sounds\\mysound.mid")
def playMIDI():
midi.play()
print "PlayMIDI returns.."
playMIDI()

As you can see, the audio module takes care of handling different
types of sounds automatically, so you can open any sound file that is
supported by your phone in a similar way. A blocking MIDI player would
look exactly like the blocking MP3 player in Example 24.

No comments:

Post a Comment