Home   Archive   Permalink



using mp3-player-libwmp.r

Hi Nick, great tutorial. I am trying to use the using mp3-player-libwmp.r code to get the metadata (ID3V2.x) song title and artist but can't seem to work out how to do this. Can you help? Note that the libwmp3.dll dll is not longer supported but I don't need to use the new version, just get this version working. Thanks

posted by:   David-MP3       3-May-2011/16:13:17-7:00



Here is the VB code for ' get ID3 field (from the libwmp3.dll documentation):
    
     Public Const ID3_VERSION2 As Integer = 2
     Public Const ID3_VERSION1 As Integer = 1
    
     Public Const ID3_TITLE As Integer = 1
     Public Const ID3_ARTIST As Integer = 2
     Public Const ID3_ALBUM As Integer = 4
     Public Const ID3_GENRE As Integer = 8
     Public Const ID3_COMMENT As Integer = 16
     Public Const ID3_TRACKNUM As Integer = 32
     Public Const ID3_YEAR As Integer = 64
    
     Private Declare Function Mp3_GetID3Field Lib "libwmp3.dll" (ByVal objptr As Integer, _
                                                             ByVal nId3Version As Integer, _
                                                             ByVal nFieldID As Integer, _
                                                             ByVal pBuffer As String, _
                                                             ByVal nSize As Integer) As Integer
    
     '
    
     '    PARAMETERS:
     '        objptr
     '            Pointer to class instance.
     '
     '        nId3Version
     '            Specifies ID3 version. Value ID3_VERSION1 loads ID3v1 data.
     '            Value ID3_VERSION2 loads ID3v2 data.
     '
     '        nFieldID
     '            Specifies ID3 field you need to retreivie.
     '
     '            ID3_TITLE        - retreive song title
     '            ID3_ARTIST        - retreive song artist
     '            ID3_ALBUM        - retreive album
     '            ID3_GENRE        - retreive genre
     '            ID3_COMMENT        - retreive comment
     '            ID3_TRACKNUM    - retreive track number
     '            ID3_YEAR        - retreive year
     '            
     '
     '        pBuffer
     '            Pointer to buffer receiving NULL terminated ID3 field string.    
     '            If this value is zero, the function returns the required buffer size, in bytes,
     '            and makes no use of the pBuffer.
     '
     '        nSize
     '            Size of receiving buffer.
     '            If this value is zero, the function returns the required buffer size, in bytes,
     '            and makes no use of the pBuffer.
     '
     '    RETURN VALUES:
     '        If pBuffer or nSize is zero, the function returns the required buffer size, in bytes.
     '        If the function succeeds, the return value is number of bytes copied into pBuffer.
     '        If function fails, return value is 0;
    
    
Here are the constants and function definition, in REBOL syntax:
    
ID3_VERSION2: 2
ID3_VERSION1: 1
ID3_TITLE: 1
ID3_ARTIST: 2
ID3_ALBUM: 4
ID3_GENRE: 8
ID3_COMMENT: 16
ID3_TRACKNUM: 32
ID3_YEAR: 64
    
Mp3_GetID3Field: make routine! [
     objptr [integer!]
     nId3Version [integer!]
     nFieldID [integer!]
     pBuffer [string!]
     nSize [integer!]
     return: [integer!]
] lib "Mp3_GetID3Field"
    
    
To understand how to use the pBuffer, you may want to take a look at the discussion at http://synapse-ehr.com/forums/showthread.php?300-How-to-call-external-Windows-library , particularly the text about "Using C Pointers" from http://www.rebol.com/docs/library.html:
    
When you pass pointers to an external library function, the function can change the values of the pointers. To determine which pointer values were changed by an external library function, use the following method:
    
Use second on the routine! value, which returns a structure.
Then, use first on the struct! returned from second. This returns a block of the potentially changed values that were passed to the external library function.

posted by:   Nick       6-May-2011/4:56:28-7:00



This should work:
    
album-text: (make string! 65)
buffer-size: Mp3_GetID3Field initialized 1 4 album-text 0
Mp3_GetID3Field initialized 1 4 album-text buffer-size
print mold fourth second first :Mp3_GetID3Field

posted by:   Nick       6-May-2011/5:49:26-7:00



Thanks for the response Nick.
Without trying to understand it too much, I did the following to see if I could get any of the tags back.
1) added your function declarations after Mp3_Close .....
==========================
Mp3_Close: make routine! [
     return: [integer!]
     initialized [integer!]
] lib "Mp3_Close"
; .. inserted here ............
ID3_VERSION2: 2
ID3_VERSION1: 1
ID3_TITLE: 1
ID3_ARTIST: 2
ID3_ALBUM: 4
ID3_GENRE: 8
ID3_COMMENT: 16
ID3_TRACKNUM: 32
ID3_YEAR: 64
        
Mp3_GetID3Field: make routine! [
     objptr [integer!]
     nId3Version [integer!]
     nFieldID [integer!]
     pBuffer [string!]
     nSize [integer!]
     return: [integer!]
] lib "Mp3_GetID3Field"
==========================    
Then added the 'this should work' code after your first call to mp3_play. Once I have selected the song, it does indeed play so that part isn't broken
==========================
print "Here are a few example functions (after 10 seconds of play):^/"
    
wait 10
print "pause"
Mp3_Pause initialized
    
album-text: (make string! 65)
buffer-size: Mp3_GetID3Field initialized 1 4 album-text 0
Mp3_GetID3Field initialized 1 4 album-text buffer-size
print mold fourth second first :Mp3_GetID3Field
================================================
    
It crashes and I'm am using Rebol/view 2.7.8
I've tried it on several mp3 files and they all crash. That is ID3V1 and ID3V2 files.
Did I do this correctly?


posted by:   David-MP3       6-May-2011/11:33:43-7:00



Is there no help on this topic?

posted by:   David-MP3       12-May-2011/13:53:39-7:00



Nick or anybody else ...any help here?

posted by:   David-MP3       17-May-2011/10:25:28-7:00