dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Applets
Expertise: Beginner
Mar 20, 1997

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Creating Java Applet to Play .au File on Startup

Question:
I am trying to create a Java routine to play an .au file when it 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 to compile. 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 user visits 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 on your Web page -- the width and height can be zero:

        
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date