簡體   English   中英

如何將 mp3 文件存儲在內存中,然后在 Java 中從那里播放

[英]How to store a mp3 file in memory and then play it from there in Java

我有一個以 BLOB 格式存儲 mp3 文件的數據庫。 我想從數據庫中檢索這些 BLOB,而不是將它們寫入硬盤,我想將它們從 BLOB 格式轉換為內存中的 MP3 文件,然后從該內存位置播放它。 它的整個想法不是將其存儲在本地機器上。 請指導我實現這一目標的任何文章或教程。

據我了解,您希望將此 mp3 文件存儲在 BLOB 中並將其作為音頻播放。

據我所知,這樣的事情應該有效。

// "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

正如評論中提到的,這也可能適用於InputStream is = resultSet.getBinaryStream("..."); ,但我沒有對此進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM