Author: remi
Date: 2008-09-17 16:06:40 +0200 (Wed, 17 Sep 2008)
New Revision: 1877

Added:
   
software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPIWav.java
Modified:
   software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPI.java
Log:
* added TuxAPIWav class

Modified: 
software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPI.java
===================================================================
--- software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPI.java 
2008-09-17 13:17:12 UTC (rev 1876)
+++ software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPI.java 
2008-09-17 14:06:40 UTC (rev 1877)
@@ -32,6 +32,7 @@
        public TuxAPITTS tts;
        public TuxAPISoundFlash soundFlash;
        public TuxAPIButton button;
+       public TuxAPIWav wav;
        
        /**
         * Constructor of the class.
@@ -78,6 +79,8 @@
                soundFlash = new TuxAPISoundFlash(this);
                // Button
                button = new TuxAPIButton(this);
+               // Wav
+               wav = new TuxAPIWav(this);
        }
        
        /**
@@ -85,6 +88,7 @@
         */
        public void destroy()
        {
+               wav.destroy();
                button.destroy();
                soundFlash.destroy();
                tts.destroy();

Added: 
software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPIWav.java
===================================================================
--- 
software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPIWav.java  
                            (rev 0)
+++ 
software_suite_v2/tuxware/java-api/trunk/src/com/tuxisalive/api/TuxAPIWav.java  
    2008-09-17 14:06:40 UTC (rev 1877)
@@ -0,0 +1,179 @@
+package com.tuxisalive.api;
+
+import java.util.*;
+
+/**
+ * Class to use the 8K 8Bit Mono wave files with Tuxdroid.
+ * 
+ * @author             R�mi Jocaille
+ * @version            0.1
+ * @since              0.1
+ */
+public class TuxAPIWav
+{
+       /*
+        * Parent field
+        */
+       private TuxAPI pParent;
+       private TuxEventHandlers eventHandlers;
+       
+       /**
+        * Constructor of the class.
+        * @param parent parent object as TuxAPI
+        */
+       public TuxAPIWav(TuxAPI parent)
+       {
+               pParent = parent;
+               eventHandlers = pParent.getEventHandlers();
+       }
+       
+       /**
+        * Destructor of the class.
+        */
+       public void destroy() {}
+       
+       /*
+        * 
+        */
+       private Boolean cmdSimpleResult(String cmd)
+       {
+               Hashtable<Object,Object> varStruct = new 
Hashtable<Object,Object>();
+               Hashtable<Object,Object> varResult = new 
Hashtable<Object,Object>();
+
+               return pParent.server.request(cmd, varStruct, varResult, false);
+       }
+       
+       /**
+        * Play a wave file.
+        * (Asynchronous)
+        * 
+        * @param waveFile wave file to play.
+        * @param begin start seconds.
+        * @param end stop seconds.
+        * @return the success of the command.
+        */
+       public Boolean playAsync(String waveFile, Double begin, Double end)
+       {
+               String cmd = String.format("wav/play?path=%s&begin=%g&end=%g", 
+                               waveFile, begin, end);
+               
+               return cmdSimpleResult(cmd);
+       }
+       
+       /**
+        * Play a wave file.
+        * (Asynchronous)
+        * 
+        * @param waveFile wave file to play.
+        * @return the success of the command.
+        */
+       public Boolean playAsync(String waveFile)
+       {
+               return playAsync(waveFile, 0., 0.);
+       }
+       
+       /**
+        * Play a wave file.
+        * 
+        * @param waveFile wave file to play.
+        * @param begin start seconds.
+        * @param end stop seconds.
+        * @return the success of the command.
+        */
+       public Boolean play(String waveFile, Double begin, Double end)
+       {
+               Integer channel;
+               
+               if (!playAsync(waveFile, begin, end))
+               {
+                       return false;
+               }
+               
+               if (pParent.server.getClientLevel() == 
TuxAPIConst.CLIENT_LEVEL_ANONYME)
+               {
+                       return true;
+               }
+               
+               Boolean ret = 
eventHandlers.waitCondition(TuxAPIConst.ST_NAME_WAV_CHANNEL_START, 
+                               1.0, null, null);
+               
+               if (!ret)
+               {
+                       return false;
+               }
+               Object result[] = 
pParent.status.requestOne(TuxAPIConst.ST_NAME_WAV_CHANNEL_START);
+               
+               try
+               {
+                       channel = Integer.valueOf((String)result[0]);
+               }
+               catch (Exception e)
+               {
+                       return false;
+               }
+               System.out.println(channel);
+               String endStName = TuxAPIConst.WAV_CHANNELS_NAME_LIST[channel];
+               result = pParent.status.requestOne(endStName);
+               
+               if (((String)result[0]).equals("OFF"))
+               {
+                       eventHandlers.waitCondition(endStName, 1.0, "ON", null);
+               }
+               
+               return eventHandlers.waitCondition(endStName, 99999999., "OFF", 
null);
+       }
+       
+       /**
+        * Play a wave file.
+        * 
+        * @param waveFile wave file to play.
+        * @return the success of the command.
+        */
+       public Boolean play(String waveFile)
+       {
+               return play(waveFile, 0., 0.);
+       }
+       
+       /**
+        * Stop the current wave file.
+        * 
+        * @return the success of the command.
+        */
+       public Boolean stop()
+       {
+               String cmd = "wav/stop?";
+               
+               return cmdSimpleResult(cmd);
+       }
+       
+       /**
+        * Set the pause state of the wave player.
+        * 
+        * @param value paused or not paused.
+        * @return the success of the command.
+        */
+       public Boolean setPause(Boolean value)
+       {
+               String cmd;
+               
+               if (value)
+               {
+                       cmd = "wav/pause?value=True";
+               }
+               else
+               {
+                       cmd = "wav/pause?value=False";
+               }
+               return cmdSimpleResult(cmd);
+       }
+       
+       /**
+        * Set the current played wave to paused.
+        * 
+        * @return the success of the command.
+        */
+       public Boolean setPause()
+       {
+               return setPause(true);
+       }
+}


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to