Understanding the Windows Media Control Interface


In the previous hour , you found out that the Win32 API provides a single function, PlaySound() , that makes it possible to play wave sounds with very little effort. Unfortunately, there is no such function available for playing MIDI music. The Win32 API groups MIDI music with other kinds of multimedia objects such as video clips. In order to play a MIDI song in a Windows program, you have to work with a special multimedia API known as the Media Control Interface , or MCI . The Media Control Interface is a high-level API that allows you to control multimedia devices such as a MIDI synthesizer or a video player. Because the MCI is so versatile in supporting a lot of different multimedia objects and devices, the MCI API is somewhat complex. The good news is that I'm going to carefully steer you through the MCI API and highlight only the portions you need in order to play MIDI music in games .

The idea behind the MCI is that you communicate with a multimedia device by sending it commands. A command is simply an instruction to carry out a particular action such as playing, pausing, or stopping a song or video clip. Two kinds of commands are actually supported by the MCI: command messages and command strings. Both approaches work equally well, but for the sake of simplicity, I opted to use command messages to communicate with the MIDI synthesizer device throughout this hour. A command message basically allows you to have a conversation with a multimedia device by sending it a message that tells it what to do. So, if you want to play a song, you would send a command message that includes the name of the song file along with the play command. I'm simplifying things a little here, but hopefully you get the idea.

Keep in mind that the Win32 API also supports a low-level programming interface that allows you to dig really deep into the details of multimedia programming. For example, you could use low-level multimedia functions to develop your own music editing software. However, the low-level multimedia API is extremely complex, so I don't recommend working with it until you have considerable experience with multimedia programming. Fortunately, you can accomplish everything you need for games without having to resort to low-level multimedia programming. Just use the MCI.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net