Jump to content
  • Advertisement
Sign in to follow this  

VB6 Playing Midi problem

This topic is 4768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I add Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _ (ByVal lpszName As String, ByVal hModule As Long, _ ByVal dwFlags As Long) As Long to my general declarations I can play wave files by adding dim Retval as long Retval = PlaySound("C:\Program Files\sounds\winline", 0, 1) but if the file is midi it won't play. Does anyone know how I can play a midi file? the following web site shows how to do it but I can't get it to play my file. http://internettrash.com/users/fdb/apimidi.htm My file is called GAMEMID so if you post the sode please show me where to put the file name I appreciate all help Thanks [Edited by - Marz on April 26, 2005 5:40:17 PM]

Share this post


Link to post
Share on other sites
Advertisement
Back when I used VB, I think I used mci for midi files

Private 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

is the declaration.
A few functions I found online are the following. It seemed to work for lots of different multimedia, not just MIDI.



Public Function OpenMultimedia(hWnd As Long, AliasName As String, filename As String, typeDevice As String) As String
'Callig OpenMultimedia will open the multimedia file
'Parameters
'hWnd
'[in]handle of the window
'which you want to play in. you can put handle for
'your desktop if you want to playing movie in your desktop.

'AliasName
'[in]Specifies name for every multimedia file and it
'should be difference e.g.:
'you want to play two multimedia files the first maybe
'named "audio1" then you should name the other difference.

'filename
'[in]Specifies file name and the path it can contain any space
'which you want to play.

'typeDevice
'[in] Specifies a type of MCI device and it could be from the following:
'Type MCI description driver file
'sequencer dealing with mid mciseq.drv
' files
'MPEGVideo dealing with most multimedia mciqtz.drv
' like mpg,mp3,mp2..
' au,aiff,..etc also support
' avi,vob(for DVD),midi,mid
' and rmi files.because of this
' my advice to you to use
' type "MPEGVideo" to playing
' MOST FILES even avi!!
' I got this info from my
' experiment when I opened
' System.ini in section MCI
' Then I must share others.
'avivideo deling with avi movie mciavi.drv

'the following types if you had ATI RAGE II or Later
'(This VGA Card to Support DVD Video)

'DvdVideo This support DVD's Video MciCinem.drv DVD
'ATIMPEGVIDEO to playing MPEG Video mciatim1.drv

'But my advice to you to not use type "ATIMPEGVIDEO" & "DvdVideo" because
'Type MPEGVideo can support most Multimedia files and also support DVD's
'Video if you had ATI RAGE II or LATER.
'last note for DVD Video: you must have a fast computer

'note : Type "MpegVideo" support these extensions:
'qt , mov, dat,snd, mpg, mpa, mpv, enc, m1v, mp2,mp3, mpe, mpeg, mpm
'au , snd, aif, aiff, aifc,wav,wmv,wma,avi,midi,mid,rmi,avi,etc.

'Note if there are any new type in (system.ini in windows 98 or in registry in windows 2000)
'it will supported by Type "MPEGVideo" because of this use type "MPEGVideo" to playing
'Most Files and remember you can use sequencer for mid and avivideo for avi,,etc.

'Now you must note using Type "MPEGVideo" can playing all Multimedia files

'Note : if this Function success will return value string "Success"
'or if not will return value string description the error which occur

'Okay make sure if you used this function don't forget to use function
'CloseMultimedia or CloseAll When you will end your program or you
'will got error message

Dim cmdToDo As String * 255
Dim dwReturn As Long
Dim ret As String * 128
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFile As String
Const WS_CHILD = &H40000000

lenShort = GetShortPathName(filename, tmp, 255)
ShortPathAndFile = left$(tmp, lenShort) 'cut short path from buffer


cmdToDo = "open " & ShortPathAndFile & " type " & typeDevice & " Alias " & AliasName & " parent " & hWnd & " Style " & WS_CHILD
dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)

If Not dwReturn = 0 Then 'not success
mciGetErrorString dwReturn, ret, 128 'Get the error
OpenMultimedia = ret: Exit Function
End If

'Success
OpenMultimedia = "Success"
End Function

Public Function PlayMultimedia(AliasName As String, Optional from_where As String = "", Optional to_where As String = "") As String
'Calling PlayMultimedia will playing the multimedia file.
'Parameters

'AliasName
'[in]Specifies name alias name which you want play it
'Note : you must let this parameter the alias which you
'used it OpenMultimedia Function or this function not Success

'from_where
'[in] Specifies the first frame in playing

'to_where
'[in]Specifies the last frame in playing

'if from_where is vbNullString and the to_where is vbNullString the Function will:
'playing from the beginning to end.

'if from_where is 10 and to_where is 100 the Function will:
'playing from 10 to 100 and stop.

'if from_where is vbNullString and to_where is 100 the Function will:
'playing from the beginning to 100 and stop.

'if from_where is 104 and to_where is vbNullString the Function will:
'playing from 104 to end.

'Note :the numbers 10,100,104 is an example for from where start playing to where end playing

'Note : if this Function success will return value string "Success"
'or if not will return value string description the error which occur

If from_where = vbNullString Then from_where = 0
If to_where = vbNullString Then to_where = GetTotalframes(AliasName)

'Improtant for auto repeat
If AliasName = glo_AliasName Then
glo_from = from_where
glo_to = to_where
End If

Dim cmdToDo As String * 128
Dim dwReturn As Long
Dim ret As String * 128

cmdToDo = "play " & AliasName & " from " & from_where & " to " & to_where

dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&) 'play

If Not dwReturn = 0 Then 'not success
mciGetErrorString dwReturn, ret, 128 'get the error
PlayMultimedia = ret
Exit Function
End If

'Success
PlayMultimedia = "Success"
End Function

Public Function CloseMultimedia(AliasName As String) As String
'Calling CloseMultimedia will close the multimedia file

'Parameters

'AliasName
'[in]Specifies name alias name which you want Close it
'Note : you must let this parameter the alias which you
'used it OpenMultimedia Function or this function not Success

'you must call this function if you called OpenMultimedia
'And want to close your program or you will get an error message

'Note : if this Function success will return value string "Success"
'or if not will return value string description the error which occur

Dim dwReturn As Long
Dim ret As String * 128
dwReturn = mciSendString("Close " & AliasName, 0&, 0&, 0&) 'close

If Not dwReturn = 0 Then 'not success
mciGetErrorString dwReturn, ret, 128 'Get the error
CloseMultimedia = ret
Exit Function
End If

'Success
If AliasName = glo_AliasName Then 'if alias the same
'this mean the user close this alias then we must delete
'the timer Function
KillTimer glo_hWnd, 500
End If

CloseMultimedia = "Success"
End Function


Share this post


Link to post
Share on other sites
Quote:
Original post by Jebediah
I usually just use the MediaPlayer object or DirectX.

I don't know how to implement that I am a newbie. Could you please explain in laymen's terms?
Thanks


Share this post


Link to post
Share on other sites
Quote:
Original post by nprz
Back when I used VB, I think I used mci for midi files

Private 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

is the declaration.
A few functions I found online are the following. It seemed to work for lots of different multimedia, not just MIDI.

*** Source Snippet Removed ***


Wow this seems miles above my head. I thought I could cut and paste a couple lines under my general dec

and then use another snipet in which i paste my file path and then presto. I really need to find someone to come over and help me but VB teachers in Toronto seem few and far between.


Thanks for the help
Gawd I feel stupid

Share this post


Link to post
Share on other sites
I was able to "just paste a few lines" and get midi music to work in a simple game I made several years ago. I believe it used either playsounda or some other mci stuff.

It was simple, but the game would pause slightly when the music would loop because it wouldn't keep it in memory, and had to reload the file each time or some such nonsense.
I'll try to dig up the code when I visit my computer next.

-Michael g.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!