使用jslider播放声音以监视流式声音/音乐的长度

编程入门 行业动态 更新时间:2024-10-28 02:29:14
本文介绍了使用jslider播放声音以监视流式声音/音乐的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个音乐播放器的学校项目,并且已经创建了GUI.我的jframe上有一个jlist,它使用jfilechooser(已完成)填充其中列出的所有音乐.现在,如果我从jlist中单击一首歌曲并按下播放按钮,则该歌曲应该在jslider移动时播放,例如Windows Media Player.现在我的问题是,我不知道从哪里开始编码,以便能够播放声音/音乐(.wav,.au,.aif,.....)扩展格式.

I am creating a school project of music player and already created the GUI. I have a jlist on my jframe which populate all the musics listed in there using jfilechooser (done). Now if I clicked a song from my jlist and press the play button, the song should be play while jslider is moving like e.g. the windows media player. Now my problem is, I don't know where to start to code for me to be able to play a sound/music (.wav, .au, .aif, .....) extension format.

请问有人,这里的任何人都可以给我片段,教程或示例代码,或者如果这里有人完成了此类项目,请您分享给我一个示例供我学习...

Could someone, anyone here be able to give me a snippet, tutorial or sample code or if someone here has been done this kind of project, could you please share me a sample for me to study...

非常感谢大家....:)

Thanks so much people.... :)

推荐答案

签出javax.sound API.如果您已经有了要播放的文件,它将可以执行以下操作(记住要导入javax.sound库):

Check out the javax.sound API. If you already have a File you want to play, it would work something like this (remember to import the javax.sound libraries):

// Gets an input stream for the given file AudioInputStream ais = AudioSystem.getAudioInputStream(file); // Gets a clip that can be used for playing an audio file or stream Clip clip = AudioSystem.getClip(); // Opens the AudioInputStream in the clip clip.open(ais);

然后,您可以在Clip对象中使用诸如开始,停止和循环之类的方法来控制音频文件的播放.

You can then use methods in the Clip object like start, stop, and loop to control playback of the audio file.

更多推荐

使用jslider播放声音以监视流式声音/音乐的长度

本文发布于:2023-07-11 09:35:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   长度   流式   音乐   jslider

发布评论

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

>www.elefans.com

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