1 package org.videolan.jvlc;
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
9 import org.videolan.jvlc.listener.VolumeListener;
11 public class Audio implements AudioIntf {
13 private long libvlcInstance;
15 private native int _getTrack();
17 private native void _setTrack(int track);
19 private native int _getChannel();
21 private native void _setChannel(int channel);
23 private native boolean _getMute();
25 private native void _setMute(boolean value);
27 private native void _toggleMute();
29 private native int _getVolume();
31 private native void _setVolume(int volume);
33 private native void _install_callback();
35 private static Map objListeners = new HashMap();
37 public Audio(long instance) {
38 this.libvlcInstance = instance;
42 private void install_callaback() {
43 objListeners.put(this, new HashSet());
47 public int getTrack() throws VLCException {
51 public void setTrack(int track) throws VLCException {
55 public int getChannel() throws VLCException {
59 public void setChannel(int channel) throws VLCException {
63 public boolean getMute() throws VLCException {
67 public void setMute(boolean value) throws VLCException {
72 public void toggleMute() throws VLCException {
76 public int getVolume() throws VLCException {
80 public void setVolume(int volume) throws VLCException {
84 public boolean addVolumeListener(VolumeListener listener) {
85 HashSet listeners = (HashSet) objListeners.get(this);
86 return listeners.add(listener);
89 public boolean removeVolumeListener(VolumeListener listener) {
90 HashSet listeners = (HashSet) objListeners.get(this);
91 return listeners.remove(listener);
94 // this method is invoked natively
95 private static void wakeupListeners() {
96 Set audioObjects = objListeners.keySet();
97 Iterator audioObjectsIterator = audioObjects.iterator();
99 while (audioObjectsIterator.hasNext()) {
100 Audio audioObject = (Audio) audioObjectsIterator.next();
101 HashSet listeners = (HashSet) objListeners.get(audioObject);
103 Iterator listenerIterator = listeners.iterator();
104 while (listenerIterator.hasNext()) {
105 VolumeListener listener = (VolumeListener) listenerIterator.next();
106 listener.volumeChanged();
111 public long getInstance() {
112 return libvlcInstance;