繁体   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