• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Standalone midi or music program

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
wrongwaysg
Asked:
wrongwaysg
  • 4
  • 2
1 Solution
 
J-ManCommented:
(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
 
wrongwaysgAuthor Commented:
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
 
J-ManCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
J-ManCommented:
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
 
wrongwaysgAuthor Commented:
Hi J-Man
Accepted your comments on using a custom resource file.
0
 
J-ManCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now