在java中打开和关闭一个mp3文件(open and close a mp3 file in java)
java
我有一个程序要求用户输入并从文件夹中打开相应的mp3文件。
import java.awt.*; import java.io.*; import java.util.*; class openmp3{ public static void main(String[] args)throws Exception{ Scanner console = new Scanner(System.in); Desktop d = Desktop.getDesktop(); System.out.print("Enter song name: "); String song = console.nextLine(); File f = new File("C:\\Users\\Leo\\Music\\" + song + ".mp3"); d.open(f); } }这段代码工作正常,但有没有办法要求用户输入并关闭正在播放的音乐文件? 也许让用户输入2并关闭播放文件。
I have a program that asks for user input and opens the corresponding mp3 file from a folder.
import java.awt.*; import java.io.*; import java.util.*; class openmp3{ public static void main(String[] args)throws Exception{ Scanner console = new Scanner(System.in); Desktop d = Desktop.getDesktop(); System.out.print("Enter song name: "); String song = console.nextLine(); File f = new File("C:\\Users\\Leo\\Music\\" + song + ".mp3"); d.open(f); } }This code works fine, but is there a way to ask for user input and close the music file that's playing? Maybe have the user enter 2 and close the playing file.
最满意答案
为什么不用Java Sound来播放呢? 然后你有完全的控制权。 我使用Java Sound,JMF MP3 SPI和BigClip 。
这是DukeBox的截图:
Why not just play it using Java Sound? Then you have total control. I made DukeBox using Java Sound, the JMF MP3 SPI, and BigClip.
Here is a screenshot of DukeBox:
更多推荐
发布评论