Results 1 to 9 of 9

Thread: Playing Midi files through a Resource file [RESOLVED]

  1. #1

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Resolved Playing Midi files through a Resource file [RESOLVED]

    I know you can load wav, ico, cur, bmp, avi, txt and use them in a resource file. Does anyone know how to load and play Midi files from a resource file?
    Last edited by Keithuk; Oct 5th, 2004 at 01:36 PM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi Keithuk, I dont think you can load the midi data directly, think you have to temp save the info to disk when you want to play the midi.

    I made a sample a long time ago for someone else at this forum.

    hope that can get you going.

    VB Code:
    1. Private Sub StartSong()
    2.     Dim ret As Integer
    3.     Dim sBuffer As String
    4.    
    5.     'sSong contains the name of the temp. file
    6.     sSong = App.Path & "\miditmp.mid"
    7.     'if it exists kill it
    8.     If Dir(sSong) <> "" Then Kill sSong
    9.    
    10.     'get the file from the resource file
    11.     'and save it to disk
    12.     sBuffer = StrConv(LoadResData("TO_TOWN", "MDI"), vbUnicode)
    13.     Open sSong For Output As #1
    14.     Print #1, sBuffer
    15.     Close #1
    16.  
    17.     'start playing the song
    18.     ret = mciSendString("open " & Chr(34) & sSong & Chr(34) & " type sequencer alias to_town", 0&, 0, 0)
    19.     ret = mciSendString("play to_town", 0&, 0, 0)
    20.    
    21. End Sub
    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    u might want this too :

    VB Code:
    1. Private Sub StopSong()
    2.     Dim ret As Integer
    3.     'stop playing the song
    4.     ret = mciSendString("close to_town", 0&, 0, 0)
    5.     'delete the temp. midi file
    6.     If Dir(sSong) <> "" Then Kill sSong
    7. End Sub
    -= a peet post =-

  5. #5

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Playing Midi files through a Resource [RESOLVED]

    Thanks Peet your code works a treat.
    Last edited by Keithuk; Dec 5th, 2004 at 09:10 AM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Question

    Ok, I'm trying to get this code to work and im coming across a few problems that I don't understand.

    I've loaded a midi into a resource file, it says that It's type is "CUSTOM" and It's ID is 101. So I took the code and replaced all instances of "TO_TOWN" with 101 and all instances of "MDI" with "CUSTOM". I'm not sure if that's what I was supposed to do or not.

    I also need to know what "mciSendString" is. I just get a compile error. Thanks.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    you need the MCI API. google it or search the forums.

  8. #8
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736
    Sorry, this will sound really dumb, but what exactly is an API?

  9. #9

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    Application Programming Interface.

    It extracts information out of dll files normally.

    e.g.

    Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

    See if you have "Program Files\Microsoft Visual Studio\Common\Tools\Winapi\APILOAD.EXE" installed.
    Last edited by Keithuk; Oct 5th, 2004 at 01:34 PM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

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