Solved

Mid files

Posted on 1998-01-23
23
273 Views
Last Modified: 2008-03-06
It seems stupid but how the h ll do you activate a mid file in a VB5 program?  I have looked everywhere and cant find one helpful thing anywhere.  All I want to do is play a mid file when the app starts and then give three choices to play other ones based on the option button(radio buttons) the user chooses.  I have tried to use the shell command and it works, but it wont compile VB says mplayer.exe is protected.

thx,
Zands
0
Comment
Question by:Zands
[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
  • 12
  • 11
23 Comments
 
LVL 8

Expert Comment

by:mrmick
ID: 1452967
Check out Microsoft Knowledge Base Article ID: Q171980
Title:"HOWTO: Play MIDI Files Using API Functions"
http://premium.microsoft.com/support/kb/articles/q171/9/80.asp

0
 

Author Comment

by:Zands
ID: 1452968
The example it gave worked, but, it still gave no explaination as to what I did or how to change options within it. For example once I start the mid file I lose all control of the app until the mid file closes, is there a way to fix that?
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452969
What options are you talking about?  I thought you just wanted to play a midi file.  There are no options available.
0
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!

 

Author Comment

by:Zands
ID: 1452970
Try the page you suggested and run the code. Once the mid file starts you can do nothing till it finishes. I merely want it to play in the background while I run the setup routine. Why cant I use the midfile object??  That seems to be more what i want but I cant find any help files to explain how to call it.  I want to use option buttons to choose which one of three mid file they want to listen to while setup is copying the files, but if thier is a better way or what Im asking isnt possible, What else can I do??

p.s. The sample database you helped me with worked great!
Thx
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452971
Oh, To get the player to return immediately while playing a midi sequence - omit the "wait" use the "close" method when you wish to stop the player.  For example,

         ret = mciSendString("play canyon", 0&, 0, 0)

'Do your thing...

         ret = mciSendString("close canyon", 0&, 0, 0)
0
 

Author Comment

by:Zands
ID: 1452972
You can have this one but, when I tried to use the lost focus with      ret = mciSendString("close MI", 0&, 0, 0)
You know to like "turn it off" it didnt work. S'up?
0
 

Author Comment

by:Zands
ID: 1452973
IT keeps locking up during runtime :-(  and I still cant turn it off.
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452974
OK, give me a sec.  The midi file you're playing can't be just "MI" - what gives with this?
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452975
Are you using the following construct to open the sequencer:
"open c:\AnyFile.MID type sequencer alias MI"

because if you're not, this is likely your problem.  All commands subsequent must reference the alias name.

Note: The above example shows you how to use MI instead of canyon as the alias name.
0
 

Author Comment

by:Zands
ID: 1452976
thats what the microsoft people did so I just followed suit it really looks like this:


Private Sub Option1_Click()
    Label1.Caption = "Be Happy"
    Label3.Caption = "Smile Ty  :-)"
    Dim ret As Integer
    ret = mciSendString("open c:\Temp\BeHappy.mid type sequencer alias BeHappy", 0&, 0, 0)
    ret = mciSendString("play BeHappy", 0&, 0, 0)
End Sub

Private Sub Option2_Click()
    Label1.Caption = "Star Wars"
    Label3.Caption = "Blonde does not equal Spacey"
    Dim ret As Integer
    ret = mciSendString("open c:\Temp\StarWars.mid type sequencer alias StarWars", 0&, 0, 0)
    ret = mciSendString("play StarWars", 0&, 0, 0)
   
End Sub

Private Sub Option3_Click()
    Label1.Caption = "Mission Impossible"
    Label3.Caption = "The way Mom feels getting thru school"
    Dim ret As Integer
    ret = mciSendString("open c:\Temp\MI.mid type sequencer alias MI", 0&, 0, 0)
    ret = mciSendString("play MI", 0&, 0, 0)
End Sub

Private Sub Option1_LostFocus()
    ret = mciSendString("close Behappy", 0&, 0, 0)
End Sub

Private Sub Option2_LostFocus()
    ret = mciSendString("close StarWars", 0&, 0, 0)
End Sub

Private Sub Option3_LostFocus()
    ret = mciSendString("close MI", 0&, 0, 0)
End Sub

0
 

Author Comment

by:Zands
ID: 1452977
by the way this does not work unless I leave the word "wait" in there.

ret = mciSendString("play MI Wait", 0&, 0, 0)

When I take "wait" out it doesnt play the file at all.
0
 
LVL 8

Accepted Solution

by:
mrmick earned 70 total points
ID: 1452978
I don't know why you continue rejecting while I'm trying to help you.  Do you want me to stop?  Just comment without rejecting unless you don't want my help.

I wrote you this procedure.  Use it play all MIDI sounds.  Call it like this:

   PlayMIDI "c:\Temp\MI.mid"

OR

   PlayMIDI "c:\Temp\StarWars.mid"

OR

   PlayMID 'No arguments will stop the sequencer.

Note: You don't even need to stop one sequence to change to another.

Here's the procedure:

Sub PlayMIDI(strPathName As String)

   Static strSaveName As String

   If Not IsEmpty(strSaveName) Then 'Stop
      mciSendString "close MySound", 0&, 0&, 0&
      strSaveName = Empty
   End If

   If Len(strPathName) > 0 Then
      strSaveName = strPathName
      mciSendString " open " & strPathName & " type sequencer alias MySound", 0&, 0&, 0&
      mciSendString "play MySound", 0&, 0&, 0&
   End If

End Sub

0
 

Author Comment

by:Zands
ID: 1452979
I didnt know I could accept and still add comments.
Sorry, it wont happen again.
Ill try it and see if it works else Im going to crash.
Thx again
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452980
Zands, I wasn't saying you had to accept the answer, but while I'm working with you I'd prefer you didn't reject.  You can comment without rejecting or accepting - although, it is polite to give credit when credit is due even when you still have followup.
  Let me know how it works out.
0
 

Author Comment

by:Zands
ID: 1452981
Im bummed.  when I tried to compile it.
It said:
mciSendString " open " & strPathName & " type sequencer alias MySound", 0&, 0&,
was not optional.
got any ideas or did I do something wrong?
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452982
Did it have the third "0&" after the comma at the end?


0
 

Author Comment

by:Zands
ID: 1452983
yes
0
 

Author Comment

by:Zands
ID: 1452984
I assumed I was supposed to leave the private declaration in??

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
0
 

Author Comment

by:Zands
ID: 1452985
Private Sub PlayMIDI(strPathName As String)
    Static strSaveName As String
    If Not IsEmpty(strSaveName) Then 'Stop
       mciSendString "close MySound", 0&, 0&, 0&
       strSaveName = Empty
    End If
    If Len(strPathName) > 0 Then
       strSaveName = strPathName
       mciSendString " open " & strPathName & " type sequencer alias"
       MySound ", 0&, 0&, 0& "
       mciSendString "play MySound", 0&, 0&, 0&
    End If
End Sub


Private Sub cmdSplash_Click()
    Label1.Caption = "Pink Panther"
    Label3.Caption = "I love this song."
    'Remove CuteFTP splash screen
    SplashKiller = Shell("C:\Program Files\CuteFTP\SplashKill.exe", 0)
    PlayMIDI "c:\Temp\Pink.mid"
End Sub

Private Sub Command1_Click()
    PlayMIDI
End Sub



Private Sub Option1_Click()
    Label1.Caption = "Be Happy"
    Label3.Caption = "Smile Ty  :-)"
    PlayMIDI "c:\Temp\BeHappy.mid"
End Sub

Private Sub Option2_Click()
    Label1.Caption = "Star Wars"
    Label3.Caption = "Blonde does not equal Spacey"
    PlayMIDI "c:\Temp\StarWars.mid"
End Sub

Private Sub Option3_Click()
    Label1.Caption = "Mission Impossible"
    Label3.Caption = "The way Mom feels getting thru school"
    PlayMIDI "c:\Temp\MI.mid"
End Sub


this is what i did
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452986
The line should be this (ALL ON ONE LINE):

mciSendString " open " & strPathName & " type sequencer alias MySound ", 0&, 0&, 0&

AND

The command1 Click event should contain the following line EXACTLY, you must have the double set of quotes!

PlayMIDI ""


0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452987
Oh, and delete the following line:

MySound ", 0&, 0&, 0& " 


0
 

Author Comment

by:Zands
ID: 1452988
I got it!!!!!

mciSendString " open " & strPathName & " type sequencer alias"
MySound ", 0&, 0&, 0& " 

the " at the end cannot be there in either of these two lines
It works exactly as you said  :-)

you rule Mr Mick
Thx
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452989
No Problem.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 92
Recommendation vb6 to vb.net or others 14 205
Passing a Text Box name to a Sub 6 102
Collapse and expand table in Word 2010 2 101
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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