devxlogo

Creating Java Applet to Play .au File on Startup

Creating Java Applet to Play .au File on Startup

Question:
I am trying to create a Java routine to play an .au file whenit starts up (I want to then add this as a startup to my Web page).

I have been hacking for the last few days, but cannot get it tocompile. I think I am missing something obvious.

Answer:
Here’s an example of how to play an audio clip from an applet.The following applet plays a short audio clip whenever the uservisits that Web page:

import java.applet.*;import java.awt.*;import java.net.*;public class AudioPlay extends Applet {       String loopFile = “music.au”;       AudioClip clip;       public void init() {             clip = getAudioClip(getCodeBase(), loopFile);             start();       }       public void start() {               clip.play();       }       public void stop() {               clip.stop();       }} 
This applet doesn’t even have to consume any screen real estate onyour Web page — the width and height can be zero:
        

See also  How to Avoid Money Transfer Scams  
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist