Results 1 to 6 of 6

Thread: Play Audio in Java Applet

  1. #1
    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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)

  3. #3
    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();
        }
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    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. #5
    Join Date
    Jan 2008
    Posts
    1,521

    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. #6
    Join Date
    Apr 2008
    Posts
    2,005

    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) {}
        }

Similar Threads

  1. How to run java applet program using cmd
    By Rao's in forum Software Development
    Replies: 3
    Last Post: 07-01-2012, 03:35 PM
  2. Zoom in on a Java Applet?
    By Bharata in forum Software Development
    Replies: 6
    Last Post: 21-10-2010, 07:01 AM
  3. Java signed applet permission
    By Parvati in forum Software Development
    Replies: 4
    Last Post: 09-08-2010, 10:28 AM
  4. Java applet errors
    By Harpreet Gaur in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:08 PM
  5. Refresh Java Applet
    By Brake Fail in forum Software Development
    Replies: 6
    Last Post: 16-03-2009, 10:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,038,149.10631 seconds with 16 queries