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