Results 1 to 5 of 5

Thread: Play Midi Sounds from Resource Editor

  1. #1

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    I know how to play WAV files from here.. But how can I play the MIDI files too?

    Thank you in advance for your help.



    *** This is what I am using rightnow for the WAVES ***


    Public Sub PlayWavResource(pintResourceID As Integer)

    Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

    Private Const SND_ASYNC = &H1 ' Play asynchronously

    Private Const SND_NODEFAULT = &H2 ' Don't use default sound

    Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file

    'Usage: PlayWavResource ResourceID
    'Example: Call PlayWavResource(101)

    Dim retVal As Long
    Dim SoundBuffer As String
    SoundBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
    retVal = sndplaysound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)

    End Sub

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure thing. You can use this similar routine to play MIDI from resource:
    Code:
    Private 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
    
    Public Function PlayResourceMIDI(pintResourceID As Integer)
        Dim lRetVal As Long
        Dim strBuffer As String
        
        strBuffer = StrConv(LoadResData(pintResourceID, "CUSTOM"), vbUnicode)
        lRetVal = mciSendString("open " & strBuffer & " type sequencer Alias midifile", 0&, 0, 0)
        lRetVal = mciSendString("play midifile wait", 0&, 0, 0)
        lRetVal = mciSendString("close midifile", 0&, 0, 0)
    End Function
    Usage: PlayResourceMIDI ResourceID
    Samle: Call PlayResourceMIDI(101)

  3. #3

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    I gave it a try but it does not play. What am I doing wrong? I have another routine that I have used and it will play them for me. But I cannot access a Midi from the Resource.

    I have used:

    Dim SafeFile As String
    SafeFile$ = Dir(MIDIFile$)
    If SafeFile$ <> "" Then
    Call mciSendString("play " & MIDIFile$, 0&, 0, 0)
    End If


  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Did you copy the declaration as well?? I've tested it many times and it works just fine.

  5. #5
    Addicted Member
    Join Date
    Mar 2002
    Posts
    158
    i dont understand how u make the wave sounds play with a resouce file where do u tell the code the destination of the file in the res file

    i use 2 sound modules in the program i make
    one:
    Option Explicit
    Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    (ByVal lpsz As String, ByVal hModule As Long, ByVal z As Long) As Long

    A = PlaySound("D:\James\Yr 7 game\Sounds\Start.wav", 0, 1) 'plays a sound when the form is loaded

    i use this moduel becouse it is simple
    i ahve another module that makes sounds repeat
    Private Const SND_ASYNC = &H1 ' play asynchronously
    Private Const SND_FILENAME = &H20000 ' name is a file name
    Private Const SND_LOOP = &H8 ' loop the sound until next

    sndPlaySoundPlaySound "D:\James\Yr 7 game\Sounds\Theme.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_LOOP 'it will play this sound

    can i still play sounds with those modules or so they can repeat and etc

    HELP please
    thanks alot
    Trav

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width