[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

mciSendString notification

Posted on 1997-09-10
5
Medium Priority
?
468 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
[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
  • 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 400 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

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!

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…
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

656 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