Solved

mciSendString notification

Posted on 1997-09-10
5
421 Views
Last Modified: 2012-08-14
VB5
Trying to loop or continuously play MIDI files.  I am using the API call rather than the MCI control.
The API parameters can include 'notify' , so how can I trap the notifiy event to determine when the MIDI file has completed?
Is there a better (another) way to loop MIDI files?
Thanks for your help.
Barry
0
Comment
Question by:BWATERS
  • 3
5 Comments
 

Author Comment

by:BWATERS
ID: 1434524
Edited text of question
0
 
LVL 1

Expert Comment

by:eyvind081997
ID: 1434525
Why not use the MCI control? In the done event you can play it all over again.
0
 

Author Comment

by:BWATERS
ID: 1434526
Thanks for the quick response.
I'd rather not use the MCI control as all I am doing is playing MIDI files and do not want to add 'overhead'.  Also, strictly from a programming point of view (and a desire to learn), I find it frustrating that WAV files can be looped easily enough...why not MIDI files.
0
 

Accepted Solution

by:
Wyatt090997 earned 200 total points
ID: 1434527
Bwaters:

Below is a sample source which will loop a midi file continuously until you call it to stop. You can set the length of the midi exactly, or where inside the midi you'd like it to stop and then loop. You can also post your email address and I will send you this sample application as a zip file. This prog only needs VB Runtime (I used 4 32 bit, but you could bring it into 5 easily) and the winmm.dll as it uses the "mciSendString."

Create a new program and place 2 command buttons and a timer on form1. You will also need a Module1:

'in general declarations of Form1 place the following sub:

Sub PlayBackGround()
    'Start Background Midi
    'Play the MIDI "TEST.MID" file aliased as "MyMidi".
    result = mciSendString("open " & App.Path & "\TEST.MID type sequencer alias MyMidi", 0&, 0, 0)
   
    'Error correction. REM out when debugging
    On Error Resume Next

    'Dim result As Long
    Dim X!

    'This is where we bring it back to each time.
StartAgain:
    result = mciSendString("close all", 0&, 0, 0)
    'Reload the MIDI file.
    result = mciSendString("open " & App.Path & "\TEST.MID type sequencer alias MyMidi", 0&, 0, 0)

    'Timer settings. I guess 1000 is the default.
    Form1.Timer1.Interval = 1000
    Form1.Timer1.Enabled = True
    X! = Timer
    Do
        result = mciSendString("play MyMidi", 0&, 0, 0)
        DoEvents
   
        'Just set the length of the midi file below
        'and loop until the set time is over (length of midi).
           
    Loop While Abs(Timer - X!) <= 10 'Midi Length in seconds

        'close the midi player to avoid hanging it :-)
        result = mciSendString("close all", 0&, 0, 0)

        'Send it back to the top
        GoTo StartAgain
End Sub

'command button1:
Private Sub Play_Click()
PlayBackGround
End Sub

'command button2:
Private Sub Stop_Click()
Dim result As Long
    'Close background music
    result = mciSendString("close all", 0&, 0, 0)
End
End Sub

'place in MODULE1:

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

Public result

--------------------

Just replace TEST.MID with the name of your MIDI file OR rename your MIDI file TEST.MID. Set your midi length (10 'Midi Length in seconds) this example is 10 seconds...but you can set it to the exact length of yours (or to what point you want to loop).

Wyatt
0
 

Author Comment

by:BWATERS
ID: 1434528
Wyatt, thanks for the reponse.
Rather unique...not what I had asked, but acceptable as a solution; higher marks if you had also included a procedure/function that would  determine the length (in seconds) of different MIDI files.  Your solution assumes the programmer knows the length of the MIDI file being played.n Still a chance to go to the head of the class.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now