The way I do this is set up the application as an appletcation, which is a hybrid of an application and an applet. You will also need to extend JApplet and use this AdapterClass shown below. Below the AdapterClass here is a sample appletcation you can use as a guide. I do not know if this is the easiest way to do this, but I do know that it works. If anyone knows of an easier way I would like to know. Thanks!!!
Barry import java.awt.*; import java.applet.*; import java.net.URL; import java.util.Enumeration; class AppletAdapter implements AppletContext,AppletStub { public URL getDocumentBase() { try { return new URL("file:" + System.getProperty("user.dir") + System.getProperty("file.separator")); } catch (Exception e) { return null; } } public AudioClip getAudioClip(URL url) { try { return Applet.newAudioClip(url); } catch (Exception e) { return null; } } public Image getImage(URL url) { return Toolkit.getDefaultToolkit().getImage(url); } public URL getCodeBase() { return getDocumentBase(); } public boolean isActive() { return true; } public AppletContext getAppletContext() { return this; } // Unimplemented methods ------------------------------- public String getParameter(String name) { return null; } public Image getImage() { return null; } public Applet getApplet(String name) { return null; } public Enumeration getApplets() { return null; } public void showDocument(URL url) { ; } public void showDocument(URL url, String target) { ; } public void showStatus(String status) { ; } public void appletResize(int width, int height) { ; } } import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class MediaAppletcation extends JApplet { Image theImage; AudioClip theClip; public void init() { Container c = getContentPane(); theClip = getAudioClip(getDocumentBase(), "Music.au"); theImage = getImage(getDocumentBase(), "pizza.jpg"); } public void paint(Graphics g) { int w = getSize().width - (getInsets().left + getInsets().right); int h = getSize().height - (getInsets().top + getInsets().bottom); super.paint(g); if (theImage == null | | !g.drawImage( theImage, getInsets().left, getInsets().top, w, h, this)) repaint(300); } public void start() { theClip.loop(); } public void stop() { theClip.stop(); } public static void main(String [] args) { MediaAppletcation applet = new MediaAppletcation(); applet.setStub(new AppletAdapter()); JFrame theFrame = applet.new MainFrame("The MediaAppletcation"); theFrame.getContentPane().add(applet, "Center"); theFrame.show(); applet.init(); applet.start(); applet.invalidate(); applet.validate(); } class MainFrame extends JFrame { public MainFrame(String title) { super(title); setSize(500, 400); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } } }
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Sound Play Back in Java stand alone Application?