Rev 206 | Rev 265 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 206 | Rev 229 | ||
---|---|---|---|
1 | /****************************************** |
1 | /****************************************** |
2 | * |
2 | * |
3 | * Voice output for MK |
3 | * Voice output for MK |
4 | * |
4 | * |
5 | * Author: Marcus -LiGi- Bueschleb |
5 | * Author: Marcus -LiGi- Bueschleb |
6 | * |
6 | * |
7 | *******************************************/ |
7 | *******************************************/ |
8 | 8 | ||
9 | import javax.microedition.media.*; |
9 | import javax.microedition.media.*; |
10 | import javax.microedition.media.control.*; |
10 | import javax.microedition.media.control.*; |
11 | import java.util.*; |
11 | import java.util.*; |
12 | import java.io.*; |
12 | import java.io.*; |
13 | 13 | ||
14 | 14 | ||
15 | public class MKStatusVoice |
15 | public class MKStatusVoice |
16 | implements Runnable,PlayerListener |
16 | implements Runnable,PlayerListener |
17 | { |
17 | { |
18 | 18 | ||
19 | org.ligi.ufo.MKCommunicator mk=null; |
19 | org.ligi.ufo.MKCommunicator mk=null; |
20 | DUBwiseCanvas canvas=null; |
20 | DUBwiseCanvas canvas=null; |
21 | Player player; |
21 | Player player; |
22 | 22 | ||
23 | public final int PLAYERSTATE_IDLE=0; |
23 | public final int PLAYERSTATE_IDLE=0; |
24 | public final int PLAYERSTATE_PLAYING=1; |
24 | public final int PLAYERSTATE_PLAYING=1; |
25 | public final int PLAYERSTATE_FIN=2; |
25 | public final int PLAYERSTATE_FIN=2; |
- | 26 | ||
- | 27 | ||
- | 28 | public int volume=100; |
|
- | 29 | public int delay=5; |
|
26 | 30 | ||
27 | int act_player_state=PLAYERSTATE_IDLE; |
31 | int act_player_state=PLAYERSTATE_IDLE; |
28 | VolumeControl vc; |
32 | VolumeControl vc; |
29 | 33 | ||
30 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
34 | public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas) |
31 | { |
35 | { |
32 | canvas=_canvas; |
36 | canvas=_canvas; |
33 | mk=_mk; |
37 | mk=_mk; |
34 | new Thread( this ).start(); // fire up main Thread |
38 | new Thread( this ).start(); // fire up main Thread |
35 | } |
39 | } |
36 | 40 | ||
37 | public void playerUpdate(Player player, String event, Object data) |
41 | public void playerUpdate(Player player, String event, Object data) |
38 | { |
42 | { |
39 | if(event == PlayerListener.END_OF_MEDIA) { |
43 | if(event == PlayerListener.END_OF_MEDIA) { |
40 | try { |
44 | try { |
41 | defplayer(); |
45 | defplayer(); |
42 | } |
46 | } |
43 | catch(MediaException me) { } |
47 | catch(MediaException me) { } |
44 | act_player_state=PLAYERSTATE_FIN; |
48 | act_player_state=PLAYERSTATE_FIN; |
45 | player=null; |
49 | player=null; |
46 | 50 | ||
47 | } |
51 | } |
48 | } |
52 | } |
49 | 53 | ||
50 | void defplayer() throws MediaException { |
54 | void defplayer() throws MediaException { |
51 | if (player != null) { |
55 | if (player != null) { |
52 | if(player.getState() == Player.STARTED) { |
56 | if(player.getState() == Player.STARTED) { |
53 | player.stop(); |
57 | player.stop(); |
54 | } |
58 | } |
55 | if(player.getState() == Player.PREFETCHED) { |
59 | if(player.getState() == Player.PREFETCHED) { |
56 | player.deallocate(); |
60 | player.deallocate(); |
57 | } |
61 | } |
58 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
62 | if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) { |
59 | player.close(); |
63 | player.close(); |
60 | } |
64 | } |
61 | } |
65 | } |
62 | player = null; |
66 | player = null; |
63 | } |
67 | } |
64 | 68 | ||
65 | 69 | ||
66 | public void start_playing(String name) |
70 | public void start_playing(String name) |
67 | { |
71 | { |
68 | try { |
72 | try { |
69 | 73 | ||
70 | try { |
74 | try { |
71 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
75 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3"); |
72 | } |
76 | } |
73 | catch (Exception e) { |
77 | catch (Exception e) { |
74 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
78 | player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav"); |
75 | } |
79 | } |
76 | player.addPlayerListener(this); |
80 | player.addPlayerListener(this); |
77 | player.realize(); |
81 | player.realize(); |
78 | act_player_state=PLAYERSTATE_PLAYING; |
82 | act_player_state=PLAYERSTATE_PLAYING; |
79 | 83 | ||
80 | vc = (VolumeControl) player.getControl("VolumeControl"); |
84 | vc = (VolumeControl) player.getControl("VolumeControl"); |
81 | if(vc != null) { |
85 | if(vc != null) { |
82 | vc.setLevel(100); |
86 | vc.setLevel(volume); |
83 | } |
87 | } |
84 | 88 | ||
85 | player.prefetch(); |
89 | player.prefetch(); |
86 | player.setLoopCount(1); |
90 | player.setLoopCount(1); |
87 | player.start(); |
91 | player.start(); |
88 | } |
92 | } |
89 | catch (Exception e) { |
93 | catch (Exception e) { |
90 | 94 | ||
91 | } |
95 | } |
92 | } |
96 | } |
93 | 97 | ||
94 | public void wait_for_end() |
98 | public void wait_for_end() |
95 | { |
99 | { |
96 | while (act_player_state!=PLAYERSTATE_FIN) |
100 | while (act_player_state!=PLAYERSTATE_FIN) |
97 | { |
101 | { |
98 | try { Thread.sleep(5); } |
102 | try { Thread.sleep(5); } |
99 | catch (Exception e) { } |
103 | catch (Exception e) { } |
100 | } |
104 | } |
101 | 105 | ||
102 | 106 | ||
103 | } |
107 | } |
104 | 108 | ||
105 | int info_from_debug_set=-1; |
109 | int info_from_debug_set=-1; |
106 | public void run() |
110 | public void run() |
107 | { |
111 | { |
108 | while(true) |
112 | while(true) |
109 | { |
113 | { |
110 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.debug_data.UBatt()!=-1)&&(!mk.force_disconnect)) |
114 | if (mk.connected&&(canvas.settings.do_sound)&&(mk.debug_data.UBatt()!=-1)&&(!mk.force_disconnect)) |
111 | { |
115 | { |
112 | int ubatt=mk.debug_data.UBatt(); |
116 | int ubatt=mk.debug_data.UBatt(); |
113 | 117 | ||
114 | if (info_from_debug_set!=mk.stats.debug_data_count) |
118 | if (info_from_debug_set!=mk.stats.debug_data_count) |
115 | { |
119 | { |
116 | info_from_debug_set=mk.stats.debug_data_count; |
120 | info_from_debug_set=mk.stats.debug_data_count; |
117 | start_playing(""+(ubatt/10)); |
121 | start_playing(""+(ubatt/10)); |
118 | wait_for_end(); |
122 | wait_for_end(); |
119 | 123 | ||
120 | if((ubatt%10)!=0) |
124 | if((ubatt%10)!=0) |
121 | { |
125 | { |
122 | start_playing("komma"); |
126 | start_playing("komma"); |
123 | wait_for_end(); |
127 | wait_for_end(); |
124 | start_playing(""+(ubatt%10)); |
128 | start_playing(""+(ubatt%10)); |
125 | wait_for_end(); |
129 | wait_for_end(); |
126 | } |
130 | } |
127 | start_playing("volt"); |
131 | start_playing("volt"); |
128 | } |
132 | } |
129 | 133 | ||
130 | } |
134 | } |
- | 135 | ||
- | 136 | try { |
|
131 | 137 | if (delay<1) |
|
- | 138 | Thread.sleep(1000); |
|
- | 139 | else |
|
- | 140 | Thread.sleep(delay*1000); |
|
132 | try { Thread.sleep(5000); } |
141 | } |
133 | catch (Exception e) { } |
142 | catch (Exception e) { } |
134 | 143 | ||
135 | } |
144 | } |
136 | } |
145 | } |
137 | 146 | ||
138 | 147 | ||
139 | 148 | ||
140 | } |
149 | } |
141 | 150 |