Subversion Repositories Projects

Rev

Rev 129 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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