.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Applet to play sound

Posted By:satyapriyanayak       Posted Date: June 30, 2014    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

In this Code Snippets we will know how to play, repeat and stop a playing music using applet.
 

//Applet to play sound
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;

public class Musicapplet extends Applet implements ActionListener
{
    Button b1,b2,b3;
    AudioClip au;
  public void init()
     {
        Font f=new Font("Arial",Font.BOLD,25);
        setFont(f);
   try{ URL u1=new URL("file:///E:/java/airtel.au");
    au=getAudioClip(u1);
   b1=new Button("Play");
   b2=new Button("Repeat");
   b3=new Button("Stop");
 
add(b1);add(b2);add(b3);
   b1.addActionListener(this);
   b2.addActionListener(this);
   b3.addActionListener(this);
    Label   lab1=new Label("Playing  music");
    
    setBackground(Color.yellow);
    add(lab1);
}
catch(Exception  e){
   System.out.println(e);
    }

   }
  public void actionPerformed(ActionEvent ae)
   {
   Button b=(Button)ae.getSource();
   if(b==b1)
      au.play();
    else if(b==b2)
      au.loop();
    else
      au.stop();
    }
}

/*
 <applet code="Musicapplet" height="200"  width="200">
</applet>
  */

Compile

Make a directory java in any drive (E:\java). Store music files and java file into that directory.
Open command prompt and go to that directory for compiling the java file as

E:\Documents and Settings\Administrator>cd\
E:\>cd E:\java
E:\java>javac Musicapplet.java
E:\java>appletviewer Musicapplet.java


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend