Author: jerome
Date: 2009-03-06 11:10:29 +0100 (Fri, 06 Mar 2009)
New Revision: 3841
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/Configuration.java
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/listener/
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/listener/WMPThreadListener.java
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/MediaPlayerThread.java
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/WMPlayer.java
Log:
* Added listener that notify WMP started or 'start error' to the main class.
* Re factored the project.
* Loading the dll that wasn't loaded ( that why that was not working ^^ )
(dll path has still to be fixed for the gadget path).
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/Configuration.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/Configuration.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/Configuration.java
2009-03-06 10:10:29 UTC (rev 3841)
@@ -0,0 +1,67 @@
+/* This file is part of "TuxDroid Gadget Windows Media player".
+ * Copyright 2008, kysoh
+ * Author : Francois Finfe
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid Gadget Windows Media player" is free software; you can
redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid Gadget Windows Media player" is distributed in the hope that it
will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Gadget Windows Media player"; if not, write to
the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.kysoh.tuxdroid;
+
+import com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadgetConfiguration;
+
+//public class that manage a simple configuration.
+public class Configuration extends SimpleGadgetConfiguration{
+
+ // Absolute Path/ link to the program to launch
+ private String mediaPath = "";
+ private boolean userPlaylist = false;
+
+ /**
+ * This method set the local variable mediaPath.
+ * @param mediaPath : The path where found media player
+ */
+ public void setMediaPath(String mediaPath)
+ {
+ this.mediaPath = mediaPath;
+ }
+
+
+ public String getMediaPath()
+ {
+ return this.mediaPath;
+ }
+
+
+ /**
+ * Set "read/ not read" the playlist given in parameters.
+ * @param userPlaylist
+ */
+ public void setUserPlaylist(boolean userPlaylist)
+ {
+ this.userPlaylist = userPlaylist;
+ }
+
+
+ /**
+ * Return true if user wants to play given playlist.
+ * @return
+ */
+ public boolean getUserPlaylist()
+ {
+ return this.userPlaylist;
+ }
+}
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/MediaPlayerThread.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/MediaPlayerThread.java
2009-03-06 10:01:42 UTC (rev 3840)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/MediaPlayerThread.java
2009-03-06 10:10:29 UTC (rev 3841)
@@ -24,12 +24,18 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
-import com.kysoh.tuxdroid.WMPlayer.Configuration;
+import com.kysoh.tuxdroid.Configuration;
+import com.kysoh.tuxdroid.listener.WMPThreadListener;
+
public class MediaPlayerThread extends Thread implements Runnable{
- private WMPlayer.Configuration configuration;
+ private Configuration configuration;
+ private boolean startPlaylist;
+ private final Collection<WMPThreadListener> WMPThreadListeners = new
ArrayList<WMPThreadListener>();
/**
* This object starts the media player and waits the end of the thread.
@@ -38,7 +44,7 @@
{
//Getting the right path of media player.
this.configuration = configuration;
- launchWMP(startWithPlaylist);
+ this.startPlaylist = startWithPlaylist;
}
@@ -47,7 +53,14 @@
*/
public void run()
{
-
+ try
+ {
+ launchWMP(this.startPlaylist);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
@@ -58,24 +71,35 @@
* @param openfile This boolean, if true, load and play the mediafile.
If false it launch WMP but don't open the file.
* @throws Exception
*/
- private void launchWMP(boolean openfile) throws Exception
+ private void launchWMP(boolean openfile)
{
String cmd = getWMPpath();
+ if(cmd == null)
+ {
+ this.triggerStartError();
+ return;
+ }
if (openfile)
{
- cmd+=" \""+this.configuration.getMediaPath()+"\"";
+ cmd += " \""+this.configuration.getMediaPath()+"\"";
}
try
{
//Starting media player.
- Runtime.getRuntime().exec(new String[]{cmd});
+ Process p = Runtime.getRuntime().exec(new
String[]{cmd});
+ p.waitFor();
+ this.triggerStarted();
}
catch (IOException e)
{
- throw new Exception();
+ this.triggerStartError();
+ }
+ catch (InterruptedException e)
+ {
+ this.triggerStartError();
}
}
@@ -115,6 +139,58 @@
}
}
+
+ /**
+ * Trigger the 'started' event.
+ */
+ private void triggerStarted()
+ {
+ for(WMPThreadListener listener : this.WMPThreadListeners)
+ {
+ listener.WMPStarted();
+ }
+ }
+
+
+ /**
+ * Trigger the 'startError' event.
+ */
+ private void triggerStartError()
+ {
+ for(WMPThreadListener listener : this.WMPThreadListeners)
+ {
+ listener.WMPStartError();
+ }
+ }
+
+
+ /**
+ * Add a listener.
+ */
+ public void addAttituneListener(WMPThreadListener listener)
+ {
+ this.WMPThreadListeners.add(listener);
+ }
+
+
+ /**
+ * Remove registered.
+ */
+ public void removeAttituneListener(WMPThreadListener listener)
+ {
+ this.WMPThreadListeners.remove(listener);
+ }
+
+
+ /**
+ * Return registered listeners for this object.
+ * @return WMPThreadListener array.
+ */
+ public WMPThreadListener[] getAttituneListeners()
+ {
+ return WMPThreadListeners.toArray(new WMPThreadListener[0]);
+ }
+
static class StreamReader extends Thread {
private InputStream is;
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/WMPlayer.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/WMPlayer.java
2009-03-06 10:01:42 UTC (rev 3840)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/WMPlayer.java
2009-03-06 10:10:29 UTC (rev 3841)
@@ -27,7 +27,6 @@
import com.kysoh.tuxdroid.MediaPlayerThread;
import com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadget;
-import com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadgetConfiguration;
import com.tuxisalive.api.TuxAPI;
import com.tuxisalive.api.TuxAPIConst;
@@ -37,61 +36,17 @@
* @version 0.1
*/
-public class WMPlayer extends SimpleGadget<WMPlayer.Configuration>{
+public class WMPlayer extends SimpleGadget<Configuration>{
private TuxAPI tux;
private int handle;
- //public class that manage a simple configuration.
- public static class Configuration extends SimpleGadgetConfiguration{
-
- // Absolute Path/ link to the program to launch
- private String mediaPath = "";
- private boolean userPlaylist = false;
-
- /**
- * This method set the local variable mediaPath.
- * @param mediaPath : The path where found media player
- */
- public void setMediaPath(String mediaPath)
- {
- this.mediaPath = mediaPath;
- }
-
-
- public String getMediaPath()
- {
- return this.mediaPath;
- }
-
-
- /**
- * Set "read/ not read" the playlist given in parameters.
- * @param userPlaylist
- */
- public void setUserPlaylist(boolean userPlaylist)
- {
- this.userPlaylist = userPlaylist;
- }
-
-
- /**
- * Return true if user wants to play given playlist.
- * @return
- */
- public boolean getUserPlaylist()
- {
- return this.userPlaylist;
- }
- }
-
-
@Override
public void start() throws Exception
{
try
{
- new
MediaPlayerThread(this.configuration().userPlaylist,
this.configuration()).start();
+ new
MediaPlayerThread(this.configuration().getUserPlaylist(),
this.configuration()).start();
// This section connect the TuxAPI to the server
}
catch(Exception MPThreadError)
@@ -139,34 +94,22 @@
*/
public int setFocusOnWMP()
{
+
System.load("C:\\Users\\nux\\Desktop\\deps\\X10GimliNative-1.0.dll");
int handle = 0;
- int count = 0;
- while ((handle == 0) && (count <= 20))
- {
- try
- {
- handle = WindowsAPI.findWindow("WMPlayerApp",
null);
- if (handle == 0)
- {
- Thread.sleep(100);
- count++;
- }
- }
- catch (Exception e)
- {
- throwError(e);
- System.exit(0);
- }
- }
- // if a problem occur, don't loop for infinite
- if (count > 20)
+ try
{
- throwMessage("Error can't find Windows Media Player");
- return 0;
+ Thread.sleep(4000);
+ handle = WindowsAPI.findWindow("WMPlayerApp", "Windows
Media Player");
+ System.out.println("Handle value is: " + handle);
}
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
WindowsAPI.setFocus(handle);
+
int Height=400;
int Width=400;
int lParam = (Height * 2 ^ 16) + Width;
@@ -258,7 +201,7 @@
* @param timeout
* @throws Exception
*/
- public void connectToServer() throws Exception //XXX
+ public void connectToServer()
{
System.out.println("getting connected with tuxdroid server.");
@@ -278,18 +221,13 @@
}
else
{
- throw new Exception("Dongle isn't
connected to Tuxdroid");
+ throwNotification("Error: Dongle fish
doesn't seems connected");
}
}
- else
- {
-
tux.access.acquire(TuxAPIConst.ACCESS_PRIORITY_HIGH);
- throw new Exception("Server can't connect to
the dongle");
- }
}
else
{
- throw new Exception("Can't connect to the server");
+ throwNotification("Error: Can't get connected to the
Tuxdroid server");
}
}
@@ -313,6 +251,7 @@
}
else if (value.equals("VOLUMEPLUS") ||
value.equals("UP"))
{
+ System.out.println("volumeplus");
WMPIncreaseVolume(handle);
}
else if (value.equals("VOLUMEMINUS") ||
value.equals("DOWN"))
@@ -352,6 +291,5 @@
handle = setFocusOnWMP();
}
}
-
}
}
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/listener/WMPThreadListener.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/listener/WMPThreadListener.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-WMP/trunk/tuxdroid-gadget-WMP/src/com/kysoh/tuxdroid/listener/WMPThreadListener.java
2009-03-06 10:10:29 UTC (rev 3841)
@@ -0,0 +1,28 @@
+/* This file is part of "TuxDroid Gadget Windows Media player".
+ * Copyright 2008, kysoh
+ * Author : Francois Finfe
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid Gadget Windows Media player" is free software; you can
redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid Gadget Windows Media player" is distributed in the hope that it
will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Gadget Windows Media player"; if not, write to
the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.kysoh.tuxdroid.listener;
+
+public interface WMPThreadListener {
+
+ public void WMPStarted();
+ public void WMPStartError();
+}
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn