使用 JLayer 时更改 Java 中的音量
我正在使用 JLayer 播放来自互联网的 mp3 数据输入流。 如何更改输出音量?
我正在使用这段代码来播放它:
URL u = new URL(s);
URLConnection conn = u.openConnection();
conn.setConnectTimeout(Searcher.timeoutms);
conn.setReadTimeout(Searcher.timeoutms);
bitstream = new Bitstream(conn.getInputStream()/*new FileInputStream(quick_file)*/);
System.out.println(bitstream);
decoder = new Decoder();
decoder.setEqualizer(equalizer);
audio = FactoryRegistry.systemRegistry().createAudioDevice();
audio.open(decoder);
for(int i = quick_positions[0]; i > 0; i--){
Header h = bitstream.readFrame();
if (h == null){
return;
}
bitstream.closeFrame();
I'm using JLayer to play an inputstream of mp3 data from the internet. How do i change the volume of the output?
I'm using this code to play it:
URL u = new URL(s);
URLConnection conn = u.openConnection();
conn.setConnectTimeout(Searcher.timeoutms);
conn.setReadTimeout(Searcher.timeoutms);
bitstream = new Bitstream(conn.getInputStream()/*new FileInputStream(quick_file)*/);
System.out.println(bitstream);
decoder = new Decoder();
decoder.setEqualizer(equalizer);
audio = FactoryRegistry.systemRegistry().createAudioDevice();
audio.open(decoder);
for(int i = quick_positions[0]; i > 0; i--){
Header h = bitstream.readFrame();
if (h == null){
return;
}
bitstream.closeFrame();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能认为这是不可接受的 hack,但它在我编写的 MP3 播放器中有效。 它需要向 JLayer 类之一添加一小段代码。
将以下方法添加到 javazoom.jl.player.JavaSoundAudioDevice 中。
然后,这个新方法允许您使用这样的代码更改音量。
You may consider this an unacceptable hack, but it worked in an MP3 player I wrote. It requires a small code addition to one of the JLayer classes.
Add the following method to javazoom.jl.player.JavaSoundAudioDevice.
This new method then allows you to change the volume with code like this.
调整 PC 扬声器音量的另一种(非 JLayer)方法是使用 Sun/Oracle 提供的 javax.sound.sampled 包中的类。
在我的机器上,SPEAKER 是唯一支持的输出目标。
这就是我在此应用程序中实现音量控制的方式:
http://onebeartoe.com/media-players/randomjuke/filesystem/java-web-start/swing/index.jsp
请注意,我只在 MS Windows 操作系统机器上有过使用它的经验。
Another (non-JLayer) way to adjust the PC's speaker volume is to use classes in the javax.sound.sampled package provided by Sun/Oracle.
On my machine, SPEAKER was the only output target supported.
This is how I am achieving volume control in this app:
http://onebeartoe.com/media-players/randomjuke/filesystem/java-web-start/swing/index.jsp
Please note that I have only had experience with it working on MS Windows OS machines.
尝试调整均衡器的所有频段以获得您想要的音量。 也许您还可以使用 EQFunction< /a> 为此?
Try adjusting all bands of the equalizer for the volume you’re trying to get. Maybe you can also use an EQFunction for that?
我根据 ChrisH 的答案制作了自己的版本,但我没有更改 JLayer 的源代码,而是通过反射完成的:
有点粗糙,但它有效
I made my own version on ChrisH's answer, but instead of changing the source code of JLayer, I did it via reflection:
Kinda crude, but it works