<HTML>
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" by "RodStephens@vb-helper.com" for "http://www.vb-helper.com" on "1998.03.17T18:18-0800" r (n 0 s 0 v 0 l 0))'>
<HEAD>
<TITLE>VB Helper: HowTo: Play a MIDI file by using the MCI control</TITLE>
<META NAME="Author" CONTENT="Rod Stephens">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Keywords" CONTENT="MIDI, audio, MCI, multimedia">
<META NAME="Keywords" CONTENT="MIDI, audio, MCI, multimedia">
<META NAME="Description" CONTENT="VB Helper: HowTo: Play a MIDI file by using the MCI control">
<META NAME="Copyright" CONTENT="Copyright 1997-2003, Rocky Mountain Computer Consulting, Inc.">
<META NAME="Rating" CONTENT="General">
<META NAME="Robots" CONTENT="All">
</HEAD>
<BODY BGCOLOR="#E1F3FF" BACKGROUND="bg_blue.jpg">
<!-- This table contains the banner, menu column, and content. -->
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<!-- ****** -->
<!-- Banner -->
<!-- ****** -->
<TR><TD>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="Left">
<TR>
<TD BACKGROUND="banner_mid.jpg"><IMG SRC="banner_l.jpg" WIDTH="410" HEIGHT="64"></TD>
<TD BGCOLOR="#E1F3FF"><IMG SRC="banner_r.jpg" WIDTH="32" HEIGHT="64"></TD>
</TR>
</TABLE>
</TD></TR>
<TR><TD> </TD></TR>
<!-- Menu column and content -->
<TR><TD>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="2" CELLPADDING="0">
<!-- *********** -->
<!-- Menu column -->
<!-- *********** -->
<TR>
<TD ALIGN="Left" VALIGN="Top">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<!-- Menu top -->
<TR>
<TD><IMG SRC="blue_ul.jpg" WIDTH="16" HEIGHT="16"></TD>
<TD><IMG SRC="blue_um.jpg" WIDTH="93" HEIGHT="16"></TD>
<TD><IMG SRC="blue_ur.jpg" WIDTH="16" HEIGHT="16"></TD>
</TR>
<!-- Menu entries -->
<TR BGCOLOR="#7FCFFF">
<TD BACKGROUND="blue_l.jpg" WIDTH="16"> </TD>
<TD><CENTER>
<A HREF="index.html"><B><FONT SIZE="+1">Home</FONT></B></A><BR>
<A HREF="search.html"><B>Search</B></A><BR>
<BR>
<A HREF="whats_new.html"><B>What's New</B></A><BR>
<A HREF="index_categories.html"><B>Index</B></A><BR>
<A HREF="books.html"><B>Books</B></A><BR>
<A HREF="links.html"><B>Links</B></A><BR>
<A HREF="http://www.topica.com/lists/VBHelperQA/read"><B>Q & A</B></A><BR>
<A HREF="newsletter.html"><B>Newsletter</B></A><BR>
<A HREF="banners.html"><B>Banners</B></A><BR>
<BR>
<A HREF="mailto:feedback@vb-helper.com"><B>Feedback</B></A><BR>
<A HREF="tip_jar.html"><B>Tip Jar</B></A><BR>
<BR>
<A HREF="feed.xml"><IMG SRC="xml_rss.jpg" BORDER="0" ALT="XML RSS Feed"></A><BR>
</CENTER></TD>
<TD BACKGROUND="blue_r.jpg" WIDTH="16"> </TD>
</TR>
<!-- Menu bottom -->
<TR>
<TD><IMG SRC="blue_ll.jpg" WIDTH="16" HEIGHT="16"></TD>
<TD><IMG SRC="blue_lm.jpg" WIDTH="93" HEIGHT="16"></TD>
<TD><IMG SRC="blue_lr.jpg" WIDTH="16" HEIGHT="16"></TD>
</TR>
<TR><TD HEIGHT="50" COLSPAN="3"> </TR></TD>
<!-- ******** -->
<!-- Partners -->
<!-- ******** -->
<!-- MVP -->
<TR><TD COLSPAN="3"><A HREF="http://www.mvps.org"><IMG SRC="mvp_logo.gif" BORDER="0"></A></TR></TD>
<TR><TD HEIGHT="20" COLSPAN="3"> </TR></TD>
<!-- MSDN VB Community -->
<TR><TD COLSPAN="3" ALIGN="Center">
<A HREF="http://msdn.microsoft.com/vbasic/community/default.aspx">MSDN Visual Basic Community</A>
</TD></TR>
<TR><TD HEIGHT="50" COLSPAN="3"> </TR></TD>
<!-- Amazon Recommends -->
<TR><TD COLSPAN="3" ALIGN="Center">
<!-- -->
<SCRIPT SRC="http://rcm.amazon.com/e/cm?t=vbhelper&l=rc1&p=2&o=1" TYPE="text/JavaScript"></SCRIPT>
<!-- -->
<NOSCRIPT>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="125">
<TR><TD>
<MAP NAME="boxmap">
<AREA SHAPE="RECT" COORDS="18, 263, 105, 274" HREF="http://rcm.amazon.com/e/cm/privacy-policy.html?o=1">
<AREA COORDS="0,0,10000,10000" HREF="http://www.amazon.com/exec/obidos/redirect-home/vbhelper">
</MAP>
<img src="http://rcm-images.amazon.com/images/G/01/associates/amzn_recommends/gnbox125x275.gif" width="125" height="275" border="0" usemap="#boxmap">
</TD></TR>
</TABLE>
</NOSCRIPT>
</TD></TR>
<TR><TD HEIGHT="50" COLSPAN="3"> </TR></TD>
<!-- Wiley -->
<TR><TD COLSPAN="3" ALIGN="Center" BACKGROUND="sandpaper.gif"><A HREF="http://service.bfast.com/bfast/click?bfmid=37920629&siteid=40078832&bfpage=computer_science" TARGET="_top"><IMG SRC="wiley_logo.gif" BORDER="0" ALIGN="Center" WIDTH="77" HEIGHT="105"></TD></TR>
<TR><TD HEIGHT="10" COLSPAN="3"> </TR></TD>
<!-- Que -->
<TR><TD COLSPAN="3" ALIGN="Center"><A HREF="http://www.quepublishing.com"><IMG SRC="que.gif" BORDER="0" ALIGN="Center" WIDTH="121" HEIGHT="36"></A></TD></TR>
<TR><TD HEIGHT="10" COLSPAN="3"> </TR></TD>
<!-- Amazon -->
<TR><TD COLSPAN="3" ALIGN="Center"><A HREF="amazon.html"><IMG SRC="amazon_logo.gif" BORDER="0" ALIGN="Center" WIDTH="68" HEIGHT="65"></A></TD></TR>
<TR><TD HEIGHT="10" COLSPAN="3"> </TR></TD>
<!-- ********** -->
<!-- More stuff -->
<!-- ********** -->
</TABLE>
</TD>
<!-- A little space between the menus and content -->
<TD WIDTH="5"> </TD>
<!-- ******* -->
<!-- Content -->
<!-- ******* -->
<TD WIDTH="100%" ALIGN="Left" VALIGN="Top">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<!-- How To Summary -->
<TR><TD>
<TABLE WIDTH="100%" BORDER="2" CELLSPACING="0" CELLPADDING="2">
<TR><TH ALIGN="Left">Title</TH><TD WIDTH="100%">Play a MIDI file by using the MCI control</TD></TR>
<TR><TH ALIGN="Left">Description</TH><TD WIDTH="100%">This example shows how to play a MIDI file by using the MCI control in Visual Basic 6.</TD></TR>
<TR><TH ALIGN="Left">Keywords</TH><TD>MIDI, audio, MCI, multimedia</TD></TR>
<TR><TH ALIGN="Left">Categories</TH><TD>Multimedia</TD></TR>
</TABLE>
</TD></TR>
<!-- Text content -->
<TR><TD> <BR></TD></TR>
<TR><TD>
When the program starts, it initializes the MCI control.
<P>
When the user clicks the Play button, the program sets the control's FileName property to the name of the MIDI file, sets Wait to True so the control opens the file synchronously, and sets Command = Open to open the file. It then sets Command = Play to play the file. It does not set Wait = True first so the play is asynchronous.
<P>
When the control finishes playing, the program closes the file and re-enables the Play button.
</TD></TR>
<!-- Code content -->
<TR><TD> <BR></TD></TR>
<TR>
<TD BACKGROUND="computer_paper.jpg">
<PRE><FONT NAME="Courier New" POINT-SIZE="10" SIZE="2">Private Sub Form_Load()
txtFilename.Text = App.Path
If Right$(txtFilename.Text, 1) <> "\" _
Then txtFilename.Text = txtFilename.Text & "\"
txtFilename.Text = txtFilename.Text & "Passport.mid"
<FONT COLOR="#008000">' Prepare the MCI control for WaveAudio.</FONT>
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "Sequencer"
End Sub
<FONT COLOR="#008000">' Open the device and play the sound.</FONT>
Private Sub cmdPlay_Click()
cmdPlay.Enabled = False
<FONT COLOR="#008000">' Set the file name.</FONT>
MMControl1.FileName = txtFilename.Text
<FONT COLOR="#008000">' Open the MCI device.</FONT>
MMControl1.Wait = True
MMControl1.Command = "Open"
<FONT COLOR="#008000">' Play the sound without waiting.</FONT>
MMControl1.Command = "Play"
End Sub
<FONT COLOR="#008000">' Close the device.</FONT>
Private Sub MMControl1_Done(NotifyCode As Integer)
MMControl1.Command = "Close"
cmdPlay.Enabled = True
End Sub</FONT></PRE>
</TD></TR>
<!-- *************** -->
<!-- Download button -->
<!-- *************** -->
<TR><TD><FONT SIZE="-2"> </FONT></TD></TR>
<TR><TD ALIGN="Center"><A HREF="HowTo/howto_mci_midi.zip"><IMG SRC="download.jpg" BORDER="0"></A></TD></TR>
<TR><TD><FONT SIZE="-2"> </FONT></TD></TR>
</TABLE> <!-- End content table -->
</TD> <!-- End content column -->
<!-- ************** -->
<!-- Google AdSense -->
<!-- ************** -->
<TD WIDTH="120" ALIGN="Right" VALIGN="Top">
<TABLE WIDTH="140" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR><TD ALIGN="Right">
<script type="text/javascript"><!--
google_ad_client = "pub-6627515316741006";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="3885326441";
google_color_border = ["5CAAFD","7ECFFE","00CC66","DDAADD"];
google_color_bg = ["7ECFFE","E1F3FF","99FF99","FFCCFF"];
google_color_link = ["0000FF","0000FF","0000FF","0000CC"];
google_color_url = ["008000","008000","0033FF","008000"];
google_color_text = ["000000","000000","000000","996699"];
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</TD></TR>
</TABLE> <!-- End Google AdSense table -->
</TD> <!-- End Google AdSense column -->
</TR> <!-- End row containing menu column and content -->
</TABLE> <!-- End table containing menu column and content -->
</TD></TR>
<!-- ****** -->
<!-- Footer -->
<!-- ****** -->
<TR><TD WIDTH="100%">
<TABLE WIDTH="100%" BORDER="0" BGCOLOR="#87CEFA" CELLSPACING="0" CELLPADDING="0">
<!-- Top row -->
<TR>
<TD BGCOLOR="#E1F3FF" ALIGN="Right" WIDTH="16"><IMG SRC="blue_ul.jpg" WIDTH="16" HEIGHT="16"></TD>
<TD BACKGROUND="blue_um.jpg" COLSPAN="2" ALIGN="Center"><FONT SIZE="-2">
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc. All rights reserved.
</FONT></TD>
<TD BGCOLOR="#E1F3FF"><IMG SRC="blue_ur.jpg" WIDTH="16" HEIGHT="16"></TD>
</TR>
<!-- Bottom row -->
<TR>
<TD BGCOLOR="#E1F3FF" ALIGN="Right" WIDTH="16"><IMG SRC="blue_ll.jpg" WIDTH="16" HEIGHT="16"></TD>
<TD BACKGROUND="blue_lm.jpg"><FONT SIZE="-2">
<SCRIPT LANGUAGE=JavaScript>document.write(document.URL)</SCRIPT></FONT></TD>
<TD BACKGROUND="blue_lm.jpg" ALIGN="Right"><FONT SIZE="-2">
Updated <SCRIPT LANGUAGE=JavaScript>document.write(document.lastModified)</SCRIPT>
</FONT></TD>
<TD BGCOLOR="#E1F3FF"><IMG SRC="blue_lr.jpg" WIDTH="16" HEIGHT="16"></TD>
</TR>
</TABLE>
</TD></TR>
</TABLE> <!-- End table containing banner, menu column + content, and footer -->
</BODY>
</HTML>