|
| |||||||||
| Tags: applet, audio, java, play |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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. |
|
#2
| ||||
| ||||
| 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:
|
|
#3
| ||||
| ||||
| 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();
}
}
} |
|
#4
| |||
| |||
| 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();
} |
|
#5
| ||||
| ||||
| 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");
} |
|
#6
| ||||
| ||||
| 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) {}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 08:01 AM |
| Adobe AIR support with Java Applet? | Head-Hunter | Windows Software | 4 | 30-06-2010 02:08 PM |
| 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 11:02 PM |