# Probleme mit VLCJ



## patrick-89 (6. Jun 2016)

Hallo zusammen,

ich nutze Ubuntu 16.04 LTS, VLCJ 3.0.1, Platform-2.5.2 und JNA-2.5.2. Installiert ist VLC 2.2.4.

Abspielen tut der Player alles nur der Equalizer macht mir Probleme.

Das ganze sieht so aus:

Wenn ich den Gain von einem Band veraendere, dann ist es so als ob der Gain max. hat. Leider geht das nicht mehr weg. Egal was fuer einen Gain ich setze, es bringt nix. Spannend ist auch, wenn ich den Gain auf max. oder auf min. setze (20 oder -20) dann hoert es sich so an als ob der Gain auf min. ist....
Das ist bei jedem Band der Fall.

Ich hoffe das Ihr mir weiterhelfen koennt!!!!

Hier mal mein TestCode:


```
package test;

import java.awt.Canvas;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.jna.Native;

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.binding.LibVlcConst;
import uk.co.caprica.vlcj.player.Equalizer;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class FensterTest {

    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();
//        m_mediaPlayer.setEqualizer(m_equalizer);

        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);
       
       
    }
}
```


```
package test;
/*
* This file is part of VLCJ.
*
* VLCJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VLCJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VLCJ.  If
public class EqualizerFrame {

} not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009-2016 Caprica Software Limited.
*/

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import uk.co.caprica.vlcj.binding.LibVlcConst;
import uk.co.caprica.vlcj.player.Equalizer;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.test.basic.SliderControl;

/**
* Separate frame to hold audio equalizer controls.
* <p>
* This is just an example, some shortcuts with regards to the slider controls have been taken.
*/
@SuppressWarnings("serial")
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;
                }
            }
        }
    }
}
```

Gruss
Patrick


----------

