+ /**
+ * Try to play the specified audio file
+ * @param inFile file to play
+ * @return true if play was successful
+ */
+ private boolean playAudioFile(File inFile)
+ {
+ boolean played = false;
+ // Try the Desktop library from java 6, if available
+ if (!played)
+ {
+ try
+ {
+ Class<?> d = Class.forName("java.awt.Desktop");
+ d.getDeclaredMethod("open", new Class[] {File.class}).invoke(
+ d.getDeclaredMethod("getDesktop").invoke(null), new Object[] {inFile});
+ //above code mimics: Desktop.getDesktop().open(audioFile);
+ played = true;
+ }
+ catch (InvocationTargetException e) {
+ System.err.println("ITE: " + e.getCause().getClass().getName() + " - " + e.getCause().getMessage());
+ played = false;
+ }
+ catch (Exception ignore) {
+ System.err.println(ignore.getClass().getName() + " - " + ignore.getMessage());
+ played = false;
+ }
+ }
+
+ // If the Desktop call failed, need to try backup methods
+ if (!played)
+ {
+ // If system looks like a Mac, try the open command
+ String osName = System.getProperty("os.name").toLowerCase();
+ boolean isMacOsx = osName.indexOf("mac os") >= 0 || osName.indexOf("darwin") >= 0;
+ if (isMacOsx)
+ {
+ String[] command = new String[] {"open", inFile.getAbsolutePath()};
+ try {
+ Runtime.getRuntime().exec(command);
+ played = true;
+ }
+ catch (IOException ioe) {}
+ }
+ }
+ return played;
+ }
+