Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 205 → Rev 206

/DUBwise/trunk/j2me/src/MKStatusVoice.java
0,0 → 1,140
/******************************************
*
* Voice output for MK
*
* Author: Marcus -LiGi- Bueschleb
*
*******************************************/
 
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.util.*;
import java.io.*;
 
 
public class MKStatusVoice
implements Runnable,PlayerListener
{
 
org.ligi.ufo.MKCommunicator mk=null;
DUBwiseCanvas canvas=null;
Player player;
public final int PLAYERSTATE_IDLE=0;
public final int PLAYERSTATE_PLAYING=1;
public final int PLAYERSTATE_FIN=2;
 
int act_player_state=PLAYERSTATE_IDLE;
VolumeControl vc;
 
public MKStatusVoice(org.ligi.ufo.MKCommunicator _mk,DUBwiseCanvas _canvas)
{
canvas=_canvas;
mk=_mk;
new Thread( this ).start(); // fire up main Thread
}
 
public void playerUpdate(Player player, String event, Object data)
{
if(event == PlayerListener.END_OF_MEDIA) {
try {
defplayer();
}
catch(MediaException me) { }
act_player_state=PLAYERSTATE_FIN;
player=null;
 
}
}
void defplayer() throws MediaException {
if (player != null) {
if(player.getState() == Player.STARTED) {
player.stop();
}
if(player.getState() == Player.PREFETCHED) {
player.deallocate();
}
if(player.getState() == Player.REALIZED || player.getState() == Player.UNREALIZED) {
player.close();
}
}
player = null;
}
 
 
public void start_playing(String name)
{
try {
try {
player = Manager.createPlayer(getClass().getResourceAsStream(name+".mp3"), "audio/mp3");
}
catch (Exception e) {
player = Manager.createPlayer(getClass().getResourceAsStream(name+".wav"), "audio/x-wav");
}
player.addPlayerListener(this);
player.realize();
act_player_state=PLAYERSTATE_PLAYING;
 
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null) {
vc.setLevel(100);
}
 
player.prefetch();
player.setLoopCount(1);
player.start();
}
catch (Exception e) {
}
}
public void wait_for_end()
{
while (act_player_state!=PLAYERSTATE_FIN)
{
try { Thread.sleep(5); }
catch (Exception e) { }
}
 
}
 
int info_from_debug_set=-1;
public void run()
{
while(true)
{
if (mk.connected&&(canvas.settings.do_sound)&&(mk.debug_data.UBatt()!=-1)&&(!mk.force_disconnect))
{
int ubatt=mk.debug_data.UBatt();
if (info_from_debug_set!=mk.stats.debug_data_count)
{
info_from_debug_set=mk.stats.debug_data_count;
start_playing(""+(ubatt/10));
wait_for_end();
if((ubatt%10)!=0)
{
start_playing("komma");
wait_for_end();
start_playing(""+(ubatt%10));
wait_for_end();
}
start_playing("volt");
}
}
 
try { Thread.sleep(5000); }
catch (Exception e) { }
}
}
 
}