Thread: MP3 file searching question

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    84

    MP3 file searching question

    OK, first, I have posted a very similar question like this before. It has been pointed out to me not to repost similar questions. I have a different one about the same thing though.

    I have recently finished a 1 semester course on C, that is how familiar I am with C, I can do some things with linked lists and arrays and simple simple simple programs... the course had its emphasis in engineering and numerical analysis....

    Anyway, I would like to write a program that can go through my mp3 collection and retrieve songs that have certain information in their file... such as all the songs that have the same album name.

    It would be nice if the program could then send these songs to an mp3 player.

    These are my questions:

    1) How advanced a project is this? Is this very very difficult to do? Would this be something to leave to a real programmer (which I am far from)

    2) Would it be too much trouble to do this on C should I look into C++ ? I've never written anything in C that does not use the DOS prompt for input out put data.

    3) Could anyone point me in the right direction as a way to start tackling this? I'm not sure where I should look and what I should look for.


    Thank You

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    1) How advanced a project is this? Is this very very difficult to do? Would this be something to leave to a real programmer (which I am far from)
    Fairly advanced but if you're capable of working with linked lists I think you'd be able to figure this one out.

    2) Would it be too much trouble to do this on C should I look into C++ ? I've never written anything in C that does not use the DOS prompt for input out put data.
    Pretty much anything you can do can be done in C, and in this case I don't think it'll be very difficult - but use the language you're most comfortable with. If you want to do this using a GUI instead of the command prompt, then look into the Win32 SDK (Google for Forger's Tutorial) - but don't forget to take things one step at a time.

    3) Could anyone point me in the right direction as a way to start tackling this? I'm not sure where I should look and what I should look for.
    Well you'll be working with mp3 files - so you have to learn how to do that. www.wotsit.org has the file format, or you may be able to find a 3rd party library somewhere.

    And I just noticed the part about actually sending these songs to an mp3 player. That's going to require some device communication skills (which are usually pretty advanced) and a good knowledge of how your mp3 player accepts incoming information - knowledge that is not all that easy to obtain. It may be as simple as copying the files like you were going from directory to directory, but if not, that'll be a very tough portion of your program.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    1) How advanced a project is this? Is this very very difficult to do? Would this be something to leave to a real programmer (which I am far from)
    It's not a very advanced project. The most complex part would be developing the GUI interface since you don't have any Windows GUI experience.
    2) Would it be too much trouble to do this on C should I look into C++ ? I've never written anything in C that does not use the DOS prompt for input out put data.
    This app can be written in C++. I would suggest that you stick with C since you already have C programming experience.
    3) Could anyone point me in the right direction as a way to start tackling this? I'm not sure where I should look and what I should look for.
    I'm assuming this is a WIN32 app. Then I would first develop a text mode program to read the MP3 file format and play the MP3. Next, I post on the Windows forum for assistance with developing a GUI front end for this app.

    IMHO, for starters, I would get a description of the MP3 file format. I believe the description can be found on a site called Wotsit. Also, the Windows VFW32 lib would probably be a good starting point for a beginner to write the MP3 player functions.


    Finally, I'm not a real programmer but I'm sure that I and others will help you to successfully complete this app as long as you put in some serious effort.

    Have fun
    Bob

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    I have to admit your project has piqued my interest. So, listed below is starter code to read your MP3 file format. I have NOT thoroughly tested the code. That is your responsibility.

    Next, I would suggest you develop a sorted doubly linked list to hold all of this info including the full path of the MP3 file. There is a demo of a sorted doubly LL on this forum somewhere that you may be able to use.

    Once the LL is developed, we then move onto the GUI interface. The GUI interface will be used to activate a commercial MP3 player of your choice to play the selected MP3.

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    struct sMP3ID3V1Struct
    {
        char szIdentity[3]; 
        char szTitle[30];
        char szArtist[30];
        char szAlbum[30];
        char szYear[4];
        char szComment[28];
        BYTE byteReserved;
        BYTE byteTrackNum;
        BYTE byteGenre;
    };
    
    char szArtist[30];
    char szTitle[30];
    char szAlbum[30];
    char szComment[28];
    char szYear[4];
    
    BOOL OpenMP3(char * pFile)
    {
        HANDLE hFile = NULL;
        if ((hFile = CreateFile(pFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL))
            != INVALID_HANDLE_VALUE)
        {
            DWORD dwNumBytesRead;
            sMP3ID3V1Struct sID3V1Struct;
            if (SetFilePointer(hFile,-128,NULL,FILE_END) != INVALID_SET_FILE_POINTER &&
                ReadFile(hFile,&sID3V1Struct,128,&dwNumBytesRead,NULL) &&
                dwNumBytesRead == 128 && memcmp(sID3V1Struct.szIdentity,"TAG",3) == 0)
            {
                memcpy(szTitle,sID3V1Struct.szTitle,30); 
                memcpy(szArtist,sID3V1Struct.szArtist,30);
                memcpy(szAlbum,sID3V1Struct.szAlbum,30); 
                szYear[4] = 0;
                memcpy( szYear,sID3V1Struct.szYear,4);
                if (sID3V1Struct.byteReserved)
                    memcpy(szComment,sID3V1Struct.szComment,30); 
                else
                    memcpy(szComment,sID3V1Struct.szComment,28); 
            }
            CloseHandle(hFile);
        }
        else
            return FALSE;
        return TRUE;
    }
    
    int main(int argc, char **argv)
    {
        if(argc > 1)
        {   
            if(OpenMP3(argv[1]))
            {
                printf("artist: %s\n",szArtist);
                printf("Title: %s\n",szTitle);
                printf("album:%s\n", szAlbum);
                printf("comment: %s\n", szComment);
                printf("year: %s\n", szYear);
            }
            else
            {
                printf("Could not open %s\n", argv[1]);
                return FALSE;
            }
        }
        else
        {
            printf("MP3 file name not on command line\n");
            return FALSE;
        }
        return TRUE;
    }

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your task can be broken down into a number of simple steps:
    1. Retrieve the search criteria from the command line.
    2. List the files in a directory. In Windows we can use FindFirstFile and FindNextFile to do this.
    3. Retrieve info from a mp3 file. Code to do this is widely available (see above).
    4. Compare the info with the given criteria.
    5. Tell the mp3 player to play the song by writing its file name to an m3u file. This simple playlist file format is supported by most mp3 software.
    6. Open the m3u file. In Windows we can use ShellExecute to open a document (in the case the m3u playlist) in the default application.
    7. Sit back and listen to the music.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Searching Binary Files for a Pattern
    By CaptainMorgan in forum C Programming
    Replies: 16
    Last Post: 06-17-2007, 06:04 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM