在java中打开和关闭一个mp3文件(open and close a mp3 file in java)

编程入门 行业动态 更新时间:2024-10-28 10:22:40
在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:

更多推荐

本文发布于:2023-04-28 08:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   java   file   close   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!