Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
212 | ligi | 1 | /************************************** |
2 | * |
||
3 | * Voice output |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | * see README for further Infos |
||
8 | * |
||
9 | * |
||
10 | **************************************/ |
||
11 | |||
12 | package org.ligi.android; |
||
13 | |||
14 | import android.media.*; |
||
15 | import android.media.MediaPlayer.*; |
||
16 | |||
17 | import org.ligi.ufo.*; |
||
18 | |||
19 | public class DUBwiseStatusVoice |
||
20 | implements Runnable |
||
21 | //,OnCompletionListener |
||
22 | { |
||
23 | |||
24 | MKCommunicator mk=null; |
||
25 | DUBwise root=null; |
||
26 | MediaPlayer player; |
||
27 | |||
28 | public final int PLAYERSTATE_IDLE=0; |
||
29 | public final int PLAYERSTATE_PLAYING=1; |
||
30 | public final int PLAYERSTATE_FIN=2; |
||
31 | |||
32 | int act_player_state=PLAYERSTATE_IDLE; |
||
33 | |||
34 | int last_sound=-1; |
||
35 | |||
36 | public DUBwiseStatusVoice(DUBwise _root) |
||
37 | { |
||
38 | |||
39 | root=_root; |
||
40 | |||
41 | new Thread( this ).start(); // fire up main Thread |
||
42 | } |
||
43 | |||
44 | public void start_playing(int resid) |
||
45 | { |
||
46 | last_sound=resid; |
||
47 | |||
48 | try { |
||
49 | player=MediaPlayer.create(root, R.raw.voice_sample_01-1+resid); |
||
50 | |||
51 | player.start(); |
||
52 | |||
53 | |||
54 | } |
||
55 | catch (Exception e) { |
||
56 | |||
57 | } |
||
58 | |||
59 | } |
||
60 | |||
61 | public void wait_for_end() |
||
62 | { |
||
63 | while (player.isPlaying()) |
||
64 | { |
||
65 | try { Thread.sleep(50); } |
||
66 | catch (Exception e) { } |
||
67 | } |
||
68 | try { Thread.sleep(50); } |
||
69 | catch (Exception e) { } |
||
70 | player.stop(); |
||
71 | player.release(); |
||
72 | |||
73 | player=null; |
||
74 | |||
75 | System.gc(); |
||
76 | try { Thread.sleep(150); } |
||
77 | catch (Exception e) { } |
||
78 | } |
||
79 | |||
80 | public void run() |
||
81 | { |
||
82 | while(true) |
||
83 | { |
||
84 | |||
85 | |||
86 | if (root.mk.connected&&(root.do_sound)&&(root.mk.debug_data.UBatt()!=-1)&&(!root.mk.force_disconnect)) |
||
87 | { |
||
88 | int ubatt=root.mk.debug_data.UBatt(); |
||
89 | |||
90 | start_playing( (ubatt/10)); |
||
91 | wait_for_end(); |
||
92 | |||
93 | if((ubatt%10)!=0) |
||
94 | { |
||
95 | start_playing( 14); |
||
96 | wait_for_end(); |
||
97 | start_playing((ubatt%10)); |
||
98 | wait_for_end(); |
||
99 | } |
||
100 | start_playing(15); |
||
101 | wait_for_end(); |
||
102 | |||
103 | } |
||
104 | |||
105 | try { Thread.sleep(5000); } |
||
106 | catch (Exception e) { } |
||
107 | |||
108 | } |
||
109 | } |
||
110 | |||
111 | |||
112 | |||
113 | } |
||
114 |