Rev 129 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
129 | 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; |
||
13 | |||
14 | import android.media.*; |
||
15 | import android.media.MediaPlayer.*; |
||
16 | |||
17 | public class DUBwiseStatusVoice |
||
18 | implements Runnable |
||
19 | //,OnCompletionListener |
||
20 | { |
||
21 | |||
22 | MKCommunicator mk=null; |
||
23 | DUBwise root=null; |
||
24 | MediaPlayer 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 | |||
32 | int last_sound=-1; |
||
33 | |||
34 | public DUBwiseStatusVoice(DUBwise _root) |
||
35 | { |
||
36 | |||
37 | root=_root; |
||
38 | |||
39 | new Thread( this ).start(); // fire up main Thread |
||
40 | } |
||
41 | |||
42 | public void start_playing(int resid) |
||
43 | { |
||
44 | last_sound=resid; |
||
45 | |||
46 | try { |
||
135 | ligi | 47 | player=MediaPlayer.create(root, R.raw.voice_sample_1-1+resid); |
129 | ligi | 48 | |
49 | player.start(); |
||
50 | |||
51 | |||
52 | } |
||
53 | catch (Exception e) { |
||
54 | |||
55 | } |
||
56 | |||
57 | } |
||
58 | |||
59 | public void wait_for_end() |
||
60 | { |
||
61 | while (player.isPlaying()) |
||
62 | { |
||
63 | try { Thread.sleep(50); } |
||
64 | catch (Exception e) { } |
||
65 | } |
||
66 | try { Thread.sleep(50); } |
||
67 | catch (Exception e) { } |
||
68 | player.stop(); |
||
69 | player.release(); |
||
70 | |||
71 | player=null; |
||
72 | |||
73 | System.gc(); |
||
74 | try { Thread.sleep(150); } |
||
75 | catch (Exception e) { } |
||
76 | } |
||
77 | |||
78 | public void run() |
||
79 | { |
||
80 | while(true) |
||
81 | { |
||
82 | |||
83 | |||
84 | if (root.mk.connected&&(root.do_sound)&&(root.mk.debug_data.UBatt()!=-1)&&(!root.mk.force_disconnect)) |
||
85 | { |
||
86 | int ubatt=root.mk.debug_data.UBatt(); |
||
87 | |||
88 | start_playing( (ubatt/10)); |
||
89 | wait_for_end(); |
||
90 | |||
91 | if((ubatt%10)!=0) |
||
92 | { |
||
93 | start_playing( 14); |
||
94 | wait_for_end(); |
||
95 | start_playing((ubatt%10)); |
||
96 | wait_for_end(); |
||
97 | } |
||
98 | start_playing(15); |
||
99 | wait_for_end(); |
||
100 | |||
101 | } |
||
102 | |||
103 | try { Thread.sleep(5000); } |
||
104 | catch (Exception e) { } |
||
105 | |||
106 | } |
||
107 | } |
||
108 | |||
109 | |||
110 | |||
111 | } |
||
112 |