Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Play Audio in Java Applet

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-02-2010
Member
 
Join Date: Nov 2009
Posts: 1,340
Play Audio in Java Applet
  

Hello, I am learning java programming language. And now I want to create an applet from which I can able to play Audio. I have tried it, but I am not able to get solution for it. If you are having any idea about it, then please help me to achieve it. It will be helpful to me. So, please provide details about it.

Reply With Quote
  #2  
Old 16-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Play Audio in Java Applet

Hello, if you want to create a applet which will play an AudioClip then you need to make use of the AudioClip class for that purpose. It will help you to achieve it.
This class will provide you method given below:
  1. public AudioClip getAudioClip(URL url)
  2. public AudioClip getAudioClip(URL url, String name)
Reply With Quote
  #3  
Old 16-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Play Audio in Java Applet

Hey, I have got the code below which will help you to play an audio in java applet. So, just make use of it, and you will able to get solution for it.
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class soundapplet extends Applet implements ActionListener{
  Button ply,stp;
  AudioClip audioclp;
  public void init()
{
    ply = new Button("  Play ");
    add(ply);
    ply.addActionListener(this);
    stp = new Button("  Stop  ");
    add(stp);
    stp.addActionListener(this);
    audioclp = getAudioClip(getCodeBase(), "audio.wav");
  }  
  public void actionPerformed(ActionEvent ae){
    Button b1 = (Button)ae.getSource();
    if (b1.getLabel() == "  Play in Loop  "){
      audioclp.ply();
    }
    else if(b1.getLabel() == "  Stop  "){
      audioclp.stp();
    }
  }
}
Reply With Quote
  #4  
Old 16-02-2010
Member
 
Join Date: May 2008
Posts: 2,008
Re: Play Audio in Java Applet

Hello, it is quiet simple. You just need to make use of the method below in your applet code and then you will able to get solution for your problem:
Code:
public void init()
 { 
AudioClip audioclip = getAudioClip(getDocumentBase(), http://www.techarena.in/audio.au"); 
audioclip.play(); 
audioclip.stop(); 
audioclip.loop(); 
}
Reply With Quote
  #5  
Old 16-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Play Audio in Java Applet

Hello, if you make use of the init method below then you will able to get the audio. You just need to add it in applet code and then call the method.
Code:
 public void init(){
    play = new Button("  Play ");
    add(play);
    play.addActionListener(this);
    stop = new Button("  Stop  ");
    add(stop);
    stop.addActionListener(this);
    audioclip = getAudioClip(getCodeBase(), "play.wav");
  }
Reply With Quote
  #6  
Old 16-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Play Audio in Java Applet

Hi, I think you must need to make use of the code below for getting the audio from the applet code. I have created it, and it will provide you help for getting your problem:

Code:
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class AppletSound extends Applet implements MouseListener
{
     AudioClip s1;
     AudioClip s2;

     public void init() 
     {
          s1 = getAudioClip(getDocumentBase(),"s1.au");
          s2 = getAudioClip(getDocumentBase(),"s2.au");
          addMouseListener(this);
          setBackground(Color.blue);
          s1.play();
     }
     public void paint(Graphics g) 
     {
          g.drawString("Click",40,40);
     }
     public void mouseClicked(MouseEvent e) 
     {
          s2.play();
     }
     public void mousePressed(MouseEvent e) {}
     public void mouseReleased(MouseEvent e) {}
     public void mouseEntered(MouseEvent e) {}
     public void mouseExited(MouseEvent e) {}
    }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Play Audio in Java Applet"
Thread Thread Starter Forum Replies Last Post
How to run java applet program using cmd Rao's Software Development 3 07-01-2012 03:35 PM
Zoom in on a Java Applet? Bharata Software Development 6 21-10-2010 07:01 AM
Java signed applet permission Parvati Software Development 4 09-08-2010 10:28 AM
Java applet errors Harpreet Gaur Software Development 5 12-01-2010 12:08 PM
Refresh Java Applet Brake Fail Software Development 6 16-03-2009 10:02 PM


All times are GMT +5.5. The time now is 01:00 AM.