使用jslider播放声音以监视流式声音/音乐的长度 [英] play sound with jslider to monitor the length of the streaming sound/music

查看:69
本文介绍了使用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播放声音以监视流式声音/音乐的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆