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