Search code examples
c#file-iomp3

Concat mp3 files in one file and retrieve any specific mp3 file


How to concat many (say 500) mp3 files into one file (any type) and then extract any specific file as mp3 format?

Currently I get all the files using this code:

int i = 0;
string[] files = new string[500];
foreach (var path in Directory.GetFiles(@"R:\abc\a\"))
{
    files[i++] = path;
}

Thanks in advance.

Update: If I can't extract any specific mp3 file then I want to extract all the mp3 files to a specified directory. ZIP, RAR etc aren't enough because I have to prevent humans to extract mp3 files without my program.


Solution

  • While a home-brewed container format (such as those suggested in other answers here) might work, I recommend using a well-known container format such as .zip. Although you wouldn't get much benefit out of compression, you'll get the file name, plus the ability for other progs to create/extract your file archive.

    If you need help on how to create .zip programmatically, research the web (and particularly StackOverflow), and if you still don't know, ask as a separate question.