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