0

i use VLCJ 3.0.1, Plattform 3.5.2 and JNA 3.5.2 under Ubuntu 14.10.

I would like to create a simple Vlcj Mediaplayer with equalizer.

The problem is, i can play the *.mp3, but when i enable the equalizer and change the gain from any band, i can hear that gain from the band up to max high. I couldn't change it to lower gain. No effect from the Slider. Only when i change the gain to max or min, the effekt is off.

Here is the Code only for testing:

FesterTest.java

public static void main(String[] args) {

     Canvas m_surface;
     EmbeddedMediaPlayer m_mediaPlayer;
     Equalizer m_equalizer;

    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
    m_surface = new Canvas();
    m_surface.setBackground(Color.black);
    m_surface.setBounds(0, 0, 1024, 600);

    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();

    m_mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
    m_mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(m_surface));

    System.out.println(mediaPlayerFactory.isEqualizerAvailable());
    m_equalizer = mediaPlayerFactory.newEqualizer();

    System.out.println(LibVlcConst.MAX_GAIN);
    System.out.println(LibVlcConst.MIN_GAIN);
    System.out.println(LibVlcConst.MIN_VOLUME);
    System.out.println(LibVlcConst.MAX_VOLUME);

    JFrame f = new JFrame();
    JPanel p = new JPanel();
    f.add(p);
    p.add(m_surface);
    f.setVisible(true);
    m_mediaPlayer.playMedia("/home/patrick/Dev/content/068-becky_g_-_shower.mp3");

    EqualizerFrame frame = new EqualizerFrame(mediaPlayerFactory.getEqualizerBandFrequencies(), mediaPlayerFactory.getEqualizerPresetNames(), mediaPlayerFactory, m_mediaPlayer, m_equalizer);
    frame.pack();
    frame.setVisible(true);
}

and EqualizerFrame:

public class EqualizerFrame extends JFrame implements ChangeListener, ActionListener, ItemListener {

private static final String BAND_INDEX_PROPERTY = "equalizerBandIndex";

private final String dbFormat = "%.2fdB";

private final MediaPlayerFactory mediaPlayerFactory;
private final MediaPlayer mediaPlayer;
private final Equalizer equalizer;

private final SliderControl preampControl;
private final SliderControl[] bandControls;

private final JToggleButton enableButton;
private final JComboBox presetComboBox;


@SuppressWarnings({ "unchecked", "rawtypes" })
public EqualizerFrame(List<Float> list, List<String> presets, MediaPlayerFactory mediaPlayerFactory, MediaPlayer mediaPlayer, Equalizer equalizer) {
    super("Equalizer");

    this.mediaPlayerFactory = mediaPlayerFactory;
    this.mediaPlayer = mediaPlayer;
    this.equalizer = equalizer;

    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(4,  4,  4,  4));
    contentPane.setLayout(new BorderLayout(0, 4));

    JPanel bandsPane = new JPanel();
    bandsPane.setLayout(new GridLayout(1, 1 + list.size(), 2, 0));

    preampControl = new SliderControl("Preamp", (int)LibVlcConst.MIN_GAIN, (int)LibVlcConst.MAX_GAIN, 0, dbFormat);
    preampControl.getSlider().addChangeListener(this);
    bandsPane.add(preampControl);

    bandControls = new SliderControl[list.size()];
    for(int i = 0; i < list.size(); i++) {
        bandControls[i] = new SliderControl(formatFrequency(list.get(i)), (int)LibVlcConst.MIN_GAIN, (int)LibVlcConst.MAX_GAIN, 0, dbFormat);
        bandControls[i].getSlider().putClientProperty(BAND_INDEX_PROPERTY, i);
        bandControls[i].getSlider().addChangeListener(this);
        bandsPane.add(bandControls[i]);
    }

    contentPane.add(bandsPane, BorderLayout.CENTER);

    JPanel controlsPane = new JPanel();
    controlsPane.setLayout(new BoxLayout(controlsPane, BoxLayout.X_AXIS));

    enableButton = new JToggleButton("Enable");
    enableButton.setMnemonic('e');
    controlsPane.add(enableButton);

    controlsPane.add(Box.createHorizontalGlue());

    JLabel presetLabel = new JLabel("Preset:");
    presetLabel.setDisplayedMnemonic('p');
    controlsPane.add(presetLabel);

    presetComboBox = new JComboBox();
    presetLabel.setLabelFor(presetComboBox);
    DefaultComboBoxModel presetModel = (DefaultComboBoxModel)presetComboBox.getModel();
    presetModel.addElement(null);
    for(String presetName : presets) {
        presetModel.addElement(presetName);
    }
    presetComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if(value != null) {
                label.setText(String.valueOf(value));
            }
            else {
                label.setText("--Select--");
            }
            return label;
        }
    });
    controlsPane.add(presetComboBox);

    contentPane.add(controlsPane, BorderLayout.SOUTH);

    setContentPane(contentPane);

    enableButton.addActionListener(this);
    presetComboBox.addItemListener(this);
}

private String formatFrequency(float hz) {
    if(hz < 1000.0f) {
        return String.format("%.0f Hz", hz);
    }
    else {
        return String.format("%.0f kHz", hz / 1000f);
    }
}

@Override
public final void actionPerformed(ActionEvent e) {
    boolean enable = enableButton.isSelected();
    if(!enable) {
        presetComboBox.setSelectedItem(null);
    }
    mediaPlayer.setEqualizer(enable ? equalizer : null);
}

@Override
public void stateChanged(ChangeEvent e) {
    if(e.getSource() instanceof JSlider) {
        JSlider slider = (JSlider)e.getSource();

        Integer index = (Integer)slider.getClientProperty(BAND_INDEX_PROPERTY);
        int value = slider.getValue();
        // Band...
        if(index != null) {
            equalizer.setAmp(index, (value / 100f));
        }
        // Preamp...
        else {
            equalizer.setPreamp(value / 100f);
        }

        if(!applyingPreset) {
            presetComboBox.setSelectedItem(null);
        }
    }
}

boolean applyingPreset;

@Override
public final void itemStateChanged(ItemEvent e) {
    String presetName = (String)presetComboBox.getSelectedItem();
    if(e.getStateChange() == ItemEvent.SELECTED) {
        if(presetName != null) {
            Equalizer presetEqualizer = mediaPlayerFactory.newEqualizer(presetName);
            if(presetEqualizer != null) {
                applyingPreset = true;
                preampControl.getSlider().setValue((int)(presetEqualizer.getPreamp() * 100f)); // FIXME
                float[] amps = presetEqualizer.getAmps();
                for(int i = 0; i < amps.length; i++) {
                    bandControls[i].getSlider().setValue((int)(amps[i] * 100f));
                }

                applyingPreset = false;
            }
        }
    }
}

}

I don't know what can i do an hope anybody can help me!!!!

Thanks Patrick

  • Does the equalizer example application in the vlcj test sources work for you? – caprica Jun 07 '16 at 07:41
  • No example work -.- I tested some example with the same result. – user3245774 Jun 07 '16 at 10:39
  • The equalizer on the vlc player works, but my code doesn't work. Why? Should i stop the player and change the settings then? – user3245774 Jun 07 '16 at 11:26
  • To be clear, you're saying that the vlcj equalizer example does *not* work? – caprica Jun 07 '16 at 11:59
  • I just tested the equalizer in the vlcj example and it works just fine for me. I do use the latest VLC built from git. – caprica Jun 07 '16 at 12:05
  • Which OS you use? Which jna and platform version you use? Can you give me the links where i can download this because i want use the same sources like you? Then i can test it!!!! Thanks – user3245774 Jun 07 '16 at 12:24
  • I have tested the "Test Player" in the sources but it is the same result.. When i change the gain a little bit, the sound is to strong and creaky. i don't understand why this doesn't work but the original vlc player works -.- – user3245774 Jun 07 '16 at 16:31
  • You are not being clear on what your specific problem is. If you push the gain too high the sound will be distorted, that is normal. – caprica Jun 07 '16 at 18:05
  • When I change the gain from the 31Hz band to 1.00 or 2.00 or 3.00 the sound will be distorted. When i change it to -3.00 or -5.00 or -15.00, it's the sams result, the sound will be distorted. – user3245774 Jun 07 '16 at 18:33
  • Well then, I can't help unfortunately. It works for me. – caprica Jun 07 '16 at 18:35
  • Ok thanks! Can you answer my question from 6h ago, which os and so on please? – user3245774 Jun 07 '16 at 18:45
  • Linux, git.videolan.org, but that is getting beyond the scope. – caprica Jun 07 '16 at 20:14
  • Thanks! Last question... Can i change the equalizer over rc from the vlc player? – user3245774 Jun 07 '16 at 20:40

0 Answers0