Solved

mciSendString notification

Posted on 1997-09-10
5
448 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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…

691 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