]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/Audio.java
f94e218dc97b4fab0fe13f96c4b6d50d2f0c4650
[vlc] / bindings / java / org / videolan / jvlc / Audio.java
1 package org.videolan.jvlc;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.Map;
7 import java.util.Set;
8
9 import org.videolan.jvlc.listener.VolumeListener;
10
11 public class Audio implements AudioIntf {
12
13         private long libvlcInstance;
14
15         private native int _getTrack();
16
17         private native void _setTrack(int track);
18
19         private native int _getChannel();
20
21         private native void _setChannel(int channel);
22
23         private native boolean _getMute();
24
25         private native void _setMute(boolean value);
26
27         private native void _toggleMute();
28
29         private native int _getVolume();
30
31         private native void _setVolume(int volume);
32
33         private native void _install_callback();
34
35         private static Map objListeners = new HashMap();
36
37         public Audio(long instance) {
38                 this.libvlcInstance = instance;
39                 install_callaback();
40         }
41
42         private void install_callaback() {
43                 objListeners.put(this, new HashSet());
44                 _install_callback();
45         }
46
47         public int getTrack() throws VLCException {
48                 return _getTrack();
49         }
50
51         public void setTrack(int track) throws VLCException {
52                 _setTrack(track);
53         }
54
55         public int getChannel() throws VLCException {
56                 return _getChannel();
57         }
58
59         public void setChannel(int channel) throws VLCException {
60                 _setChannel(channel);
61         }
62
63         public boolean getMute() throws VLCException {
64                 return _getMute();
65         }
66
67         public void setMute(boolean value) throws VLCException {
68                 _setMute(value);
69
70         }
71
72         public void toggleMute() throws VLCException {
73                 _toggleMute();
74         }
75
76         public int getVolume() throws VLCException {
77                 return _getVolume();
78         }
79
80         public void setVolume(int volume) throws VLCException {
81                 _setVolume(volume);
82         }
83
84         public boolean addVolumeListener(VolumeListener listener) {
85                 HashSet listeners = (HashSet) objListeners.get(this);
86                 return listeners.add(listener);
87         }
88
89         public boolean removeVolumeListener(VolumeListener listener) {
90                 HashSet listeners = (HashSet) objListeners.get(this);
91                 return listeners.remove(listener);
92         }
93
94         // this method is invoked natively
95         private static void wakeupListeners() {
96                 Set audioObjects = objListeners.keySet();
97                 Iterator audioObjectsIterator = audioObjects.iterator();
98                 
99                 while (audioObjectsIterator.hasNext()) {
100                         Audio audioObject = (Audio) audioObjectsIterator.next();
101                         HashSet listeners = (HashSet) objListeners.get(audioObject);
102
103                         Iterator listenerIterator = listeners.iterator();
104                         while (listenerIterator.hasNext()) {
105                                 VolumeListener listener = (VolumeListener) listenerIterator.next();
106                                 listener.volumeChanged();
107                         }
108                 }
109         }
110
111         public long getInstance() {
112                 return libvlcInstance;
113         }
114 }