Reputation: 17
I have a database that stores mp3 files in BLOB format. I would like to retrieve those BLOBs from the database and instead of writing them to the hard disk, I want to convert them, from BLOB format to an MP3 file in memory and then play it from that memory location. The whole idea of it is not to store it on local machine. Please guide me with any articles or tutorials in achieving so.
Upvotes: 0
Views: 429
Reputation: 13
From my understanding you're looking to take this mp3 file stored in BLOB and play it back as audio.
As far as I know, something like this should work.
// "Opens" up the mp3 file and stores it in memory like you said
File blobMp3File = new File("your mp3 audio filepath").getAbsoluteFile();
Clip clip = AudioSystem.getClip();
clip.open(blobMp3File);
clip.start(); // Plays the audio once
clip.close(); // Closes it whenever you're done
As mentioned in a comment, this might also work with InputStream is = resultSet.getBinaryStream("...");
, but I have not tested this.
Upvotes: 1