1 package org.videolan.jvlc;
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
9 public class Audio implements AudioIntf {
11 private long libvlcInstance;
13 private native int _getTrack();
15 private native void _setTrack(int track);
17 private native int _getChannel();
19 private native void _setChannel(int channel);
21 private native boolean _getMute();
23 private native void _setMute(boolean value);
25 private native void _toggleMute();
27 private native int _getVolume();
29 private native void _setVolume(int volume);
31 private native void _install_callback();
33 private static Map objListeners = new HashMap();
35 public Audio(long instance) {
36 this.libvlcInstance = instance;
40 private void install_callaback() {
41 objListeners.put(this, new HashSet());
45 public int getTrack() throws VLCException {
49 public void setTrack(int track) throws VLCException {
53 public int getChannel() throws VLCException {
57 public void setChannel(int channel) throws VLCException {
61 public boolean getMute() throws VLCException {
65 public void setMute(boolean value) throws VLCException {
70 public void toggleMute() throws VLCException {
74 public int getVolume() throws VLCException {
78 public void setVolume(int volume) throws VLCException {
82 public boolean addVolumeListener(VolumeListener listener) {
83 HashSet listeners = (HashSet) objListeners.get(this);
84 return listeners.add(listener);
87 public boolean removeVolumeListener(VolumeListener listener) {
88 HashSet listeners = (HashSet) objListeners.get(this);
89 return listeners.remove(listener);
92 // this method is invoked natively
93 private static void wakeupListeners() {
94 Set audioObjects = objListeners.keySet();
95 Iterator audioObjectsIterator = audioObjects.iterator();
97 while (audioObjectsIterator.hasNext()) {
98 Audio audioObject = (Audio) audioObjectsIterator.next();
99 HashSet listeners = (HashSet) objListeners.get(audioObject);
101 Iterator listenerIterator = listeners.iterator();
102 while (listenerIterator.hasNext()) {
103 VolumeListener listener = (VolumeListener) listenerIterator.next();
104 listener.volumeChanged();
109 public long getInstance() {
110 return libvlcInstance;