Looping a midi in VB

Do you have a technical question that doesn't really fit a specific console? Want some general info on electronics, hacking, making cookies, etc? Here's the place to ask! Go nuts.

Moderator: Moderators

Post Reply
Harshboy
Portablizer
Posts: 3610
Joined: Tue Oct 11, 2005 3:44 pm

Looping a midi in VB

Post by Harshboy »

Quick Question, How can i loop a midi (.mid) song in VB 6?

In a Module called Music, i have this:

Code: Select all

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
I'm using this to play:

Code: Select all

i = mciSendString("play Mid2", 0&, 0, 0)
This to stop:

Code: Select all

i = mciSendString("stop Mid2", 0&, 0, 0)
But how would i loop the song? I tried the obvious (See below:)

Code: Select all

i = mciSendString("loop Mid2", 0&, 0, 0)

...Sadly, the obvious didn't work, and I'm still stuck. Everything Plays and Stops fine, but i can't figure out how to loop. So if anyone here knows how to do it, or can recommend some good place to look, that'd be great. I've been searching Google for like 1 hour now, and nothing.

PS: It'd be nice if the loop method is compatible with the way I'm playing and stopping midis now ;)

Thanks in advance :D
marshallh
Moderator
Posts: 2987
Joined: Sat Sep 10, 2005 2:17 pm
360 GamerTag: marshallh
Location: here and there
Contact:

Post by marshallh »

Try calling

Code: Select all

mciSendString "Loop Mid2", 0&, 0, 0
right after you call the "play" command.
Image
Harshboy
Portablizer
Posts: 3610
Joined: Tue Oct 11, 2005 3:44 pm

Post by Harshboy »

What do you mean?

Something like this?

Code: Select all

i = mciSendString("play Mid2", 0&, 0, 0), mciSendString "Loop Mid2", 0&, 0, 0
Sorry, I'm just stupid :lol:

EDIT: That didn't work, nor did:

Code: Select all

i = mciSendString("play Mid2", 0&, 0, 0)
mciSendString "Loop Mid2", 0&, 0, 0
marshallh
Moderator
Posts: 2987
Joined: Sat Sep 10, 2005 2:17 pm
360 GamerTag: marshallh
Location: here and there
Contact:

Post by marshallh »

Either use DirectShow to play it, or set a timer with delay of 1000ms to check if the MIDI is done playing, and restart it.
Image
Harshboy
Portablizer
Posts: 3610
Joined: Tue Oct 11, 2005 3:44 pm

Post by Harshboy »

Care to explain the Timer Method of checking?

Sorry i have to keep asking, it's just my teacher doesn't teach about how to play anything other than .wav files (And he didn't know how to play mid files)
Post Reply