Results 1 to 2 of 2

Thread: Extract CD Audio Information

  1. #1

    Thread Starter
    Registered User
    Join Date
    May 2001
    Posts
    61

    Extract CD Audio Information

    Hello,

    Is it possible, with VB or an API, to extract the serial number, track information, and so on, from a CD?

    Thanks,
    Gabe

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    check out the mciSendString API. This gets the number of tracks on a CD...

    Paste this into a module
    VB Code:
    1. 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
    2. Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
    Place a command button on a form and paste this into the declarations section of that form
    VB Code:
    1. Dim fCDLoaded As Boolean
    2. Dim numTracks As Integer
    3. Private Function SendMCIString(cmd As String, fShowError As Boolean) As Boolean
    4.  
    5. Static rc As Long
    6. Static errStr As String * 200
    7.  
    8. rc = mciSendString(cmd, 0, 0, hWnd)
    9.  
    10. If (fShowError And rc <> 0) Then
    11.     mciGetErrorString rc, errStr, Len(errStr)
    12.     MsgBox errStr
    13. End If
    14.  
    15. SendMCIString = (rc = 0)
    16.  
    17. End Function
    18.  
    19.  
    20. Private Sub Command1_Click()
    21.  
    22. Static s As String * 30
    23.  
    24. ' Check if CD is in the player
    25. mciSendString "status cd media present", s, Len(s), 0
    26. If (CBool(s)) Then
    27.     ' Enable all the controls, get CD information
    28.     If (fCDLoaded = False) Then
    29.         mciSendString "status cd number of tracks wait", s, Len(s), 0
    30.         numTracks = CInt(Mid$(s, 1, 2))
    31.         ' If CD only has 1 track, then it's probably a data CD
    32.         If (numTracks = 1) Then
    33.             Exit Sub
    34.         Else
    35.             MsgBox "There are " & numTracks & " tracks on this CD.", vbInformation
    36.         End If
    37.     End If
    38. End If
    39.  
    40. End Sub
    41.  
    42.  
    43. Private Sub Form_Load()
    44.  
    45. ' If the cd is being used, then quit
    46. If (SendMCIString("open cdaudio alias cd wait shareable", True) = False) Then
    47.     End
    48. End If
    49.  
    50. SendMCIString "set cd time format tmsf wait", True
    51.  
    52. End Sub
    53.  
    54.  
    55. Private Sub Form_Unload(Cancel As Integer)
    56.  
    57. 'Close all MCI devices opened by this program
    58. 'Sndfx "Sound1.snd"
    59. SendMCIString "close all", False
    60.  
    61. End Sub

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