MySQL: Convert BLOB to mp3 audio file
Posted on 2010-03-27
This should be easy, but after searching for answers, it looks confusing:
I have an on line MySQL database with many small audio files stored as BLOB fields. What I want to do is display a list of the files and when the user clicks a record in the grid, the file stored in the same record as the viewed record plays. I think I can handle the playing of the audio--I've got that working.
What I DON'T know how to do is convert the BLOB data field to an MP3 or WAV file to play. Right now, the stored file is MP3, but I could change it to WAV or anything else.
I thought that there was an SQL command that could extract the data from the BLOB and in effect place it in a file or variable of the original file type. That is, if a jpg file was stored, it would be converted back to jpg. Or in my case, the stored MP3 file will be converted back so that it can be played.
QUESTION: How do I extract the mp3 file data from the BLOB record? Any additional comments about how to play it would be welcome. Especially regarding how to define a variable to store the converted data. Also, once the file is played, the temp data can be deleted, so if the extracted mp3 data is stored as a physical file, I would like to know how to delete it. Hoever, it does seem that the extracted data would be a memory variable, since that is what will be played.
These are all small sound files (there are a few thousand of them), and the point is that the user can select the file to hear by clicking on the record in a data grid, or repeater, or whatever.