Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Mid files

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
Zands
Asked:
Zands
  • 12
  • 11
1 Solution
 
mrmickCommented:
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
 
ZandsAuthor Commented:
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
 
mrmickCommented:
What options are you talking about?  I thought you just wanted to play a midi file.  There are no options available.
0
Industry Leaders: 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!

 
ZandsAuthor Commented:
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
 
mrmickCommented:
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
 
ZandsAuthor Commented:
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
 
ZandsAuthor Commented:
IT keeps locking up during runtime :-(  and I still cant turn it off.
0
 
mrmickCommented:
OK, give me a sec.  The midi file you're playing can't be just "MI" - what gives with this?
0
 
mrmickCommented:
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
 
ZandsAuthor Commented:
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
 
ZandsAuthor Commented:
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
 
mrmickCommented:
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
 
ZandsAuthor Commented:
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
 
mrmickCommented:
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
 
ZandsAuthor Commented:
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
 
mrmickCommented:
Did it have the third "0&" after the comma at the end?


0
 
ZandsAuthor Commented:
yes
0
 
ZandsAuthor Commented:
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
 
ZandsAuthor Commented:
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
 
mrmickCommented:
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
 
mrmickCommented:
Oh, and delete the following line:

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


0
 
ZandsAuthor Commented:
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
 
mrmickCommented:
No Problem.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now