在Java中更改卷使用JLayer时 [英] Changing volume in Java when using JLayer

查看:350
本文介绍了在Java中更改卷使用JLayer时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JLayer从互联网上播放mp3数据的InputStream。我要如何改变输出的音量?

我使用这个code发挥它的:

  URL U =新的URL(S);
康涅狄格州的URLConnection = u.openConnection();
conn.setConnectTimeout(Searcher.timeoutms);
conn.setReadTimeout(Searcher.timeoutms);比特流=新的比特流(conn.getInputStream()/ *新的FileInputStream(quick_file)* /);
的System.out.println(比特流);
德codeR =新德codeR();
德coder.setEqualizer(均衡器);
音频= FactoryRegistry.systemRegistry()createAudioDevice()。
audio.open(德codeR);
对(INT I = quick_positions [0];我大于0; I - ){
标题H = bitstream.readFrame();
如果(H == NULL){
返回;
}
bitstream.closeFrame();


解决方案

您可能会认为这是一个不可接受的黑客攻击,但它在MP3播放器,我写的工作。它需要一个小的code除了JLayer类之一。

添加以下方法来javazoom.jl.player.JavaSoundAudioDevice。

 公共无效setLineGain(浮点增益)
{
    如果(来源!= NULL)
    {
        FloatControl volControl =(FloatControl)source.getControl(FloatControl.Type.MASTER_GAIN);
        浮newGain = Math.min(Math.max(增益,volControl.getMinimum()),volControl.getMaximum());        volControl.setValue(newGain);
    }
}

这个新方法则可以让你改变与code这样的音量。

 如果(音频的instanceof JavaSoundAudioDevice)
{
    JavaSoundAudioDevice jsAudio =(JavaSoundAudioDevice)音频;
    jsAudio.setLineGain(yourGainGoesHere);
}

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();

解决方案

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.

public void setLineGain(float gain)
{
    if (source != null)
    {
        FloatControl volControl = (FloatControl) source.getControl(FloatControl.Type.MASTER_GAIN);
        float newGain = Math.min(Math.max(gain, volControl.getMinimum()), volControl.getMaximum());

        volControl.setValue(newGain);
    }
}

This new method then allows you to change the volume with code like this.

if (audio instanceof JavaSoundAudioDevice)
{
    JavaSoundAudioDevice jsAudio = (JavaSoundAudioDevice) audio;
    jsAudio.setLineGain(yourGainGoesHere);
}

这篇关于在Java中更改卷使用JLayer时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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