?
Solved

Standalone midi or music program

Posted on 2003-02-28
6
Medium Priority
?
265 Views
Last Modified: 2013-12-26
How do I write a vb control to play background midi which compiles into a standalone exe? The midi or music score is embedded in the main executable.
0
Comment
Question by:wrongwaysg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:J-Man
ID: 8048954
(1) First goto the Project menu and select Components.  Then put a check in the box for Microsoft MultiMedia Control.  You now have a MMC icon in your controls toolbox.

(2) Place a MMC onto your main form.

(3) Set the filename property of the MMC to the midi file you wish to play.  If you put the name in at design time, it will embed the file into your executable when you compile.

(4) In the Form_Load sub place the following:
MMControl1.visible = False 'You could just set this at design time instead of when you load.
MMControl1.Command = "Open" 'I'm not sure if you need this line. Try with and without.
MMControl1.Command = "Play"

(5) Compile the exe and run.
0
 

Author Comment

by:wrongwaysg
ID: 8062709
Hi J-Man
I tried using the MMC. I did not embedded the midi file into the exe. The minute I deleted the original midi file it did not work.
0
 
LVL 1

Expert Comment

by:J-Man
ID: 8083831
My bad; the MMC does NOT embed the file (like a picturebox would.)
There are basically 5 options now:
(1) Keep the midi file in the exe folder and reference it from there in the mmc.filename property.  But you would have to distribute the midi file with the exe.  This shouldn't be too much of a problem as midi files are very small.
(2) Create a resource file with the midi file as a custom resource.  This adds no advantage over option (1) however and would only complicate things.
(3) Use the commondialog control and in the form_load sub ask the user to select the midi file to play.  (This way you can use the same exe for any midi file, but the file would still have to be on the computer harddrive or cd-rom.)
(4) Use an OLE container control and make it type embedded (OLEType = 1-Embedded).  Then drop the data from the OLE container into the MMC.  I'm not too familiar with this control and cannot say for sure that the file will actually be embedded in the exe or not.
(5) Copy & Paste the text from the .mid file into a string variable during form_load sub, then use winmm.dll functions to play the midi file manually.  This is fairly complex also and would require some intensive learning of the winmm.dll functions and the midi format, also you would have to do all your own timing which gets even messier as the timer control is not fast enough - timeGetTime function must be used instead and converted into "ticks" which is dependent on several variables in the midi file.

It seems that option (1) or (3) would be the easiest way to go, options (4) and (5) are harder, but would probably do what you want.

By the way, the only code you actually need for option (1) is:

Option Explicit
Private Sub Form_Load()
    MMControl1.Command = "Open" 'This IS necessary.
    MMControl1.Command = "Play" 'Play the midi sequence.
End Sub
Private Sub Form_Unload(Cancel As Integer)
    MMControl1.Command = "Close" 'Close when not needed.  Save system resources.
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:J-Man
ID: 8083864
P.S.
I can provide code for option (5), however it is pretty long and would probably be easier just to e-mail you the source files or put them on my webspace.
0
 

Author Comment

by:wrongwaysg
ID: 8126071
Hi J-Man
Accepted your comments on using a custom resource file.
0
 
LVL 1

Accepted Solution

by:
J-Man earned 150 total points
ID: 8139267
If a comment has successfully helped you, please click the Accept button for the appropriate comment so I can get the points for helping and to let others know it works.  Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question