Results 1 to 7 of 7

Thread: Java Sound

  1. #1
    ehsan is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default Java Sound

    Hi every one . I used this code for play Sound in java and program run without error , but sound repeat until i close Netbean . how can i solve this problem .
    Java Code:
    import sun.audio.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    public class Sound   extends JFrame implements ActionListener{
        
         private  JFrame frame = new JFrame();
         private    JButton button = new JButton("Click Me");
         
         public Sound(){
             frame.setSize(200,200);
          
             frame.add(button);
             button.addActionListener(this);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
             
         }
            
            
        
        
        public static void main(String[] args) {
            
            Sound s = new Sound();
            
               
           
        }
        
        public static void music(){
            AudioPlayer MGP  = AudioPlayer.player;
            AudioStream BGM;
            AudioData MD;
            ContinuousAudioDataStream loop = null;
            try{
            BGM = new AudioStream(new FileInputStream("Windows.wav"));
            MD = BGM.getData();
            loop = new ContinuousAudioDataStream(MD);
            }catch(IOException error){}
            MGP.start(loop);
           }
    
            public void actionPerformed(ActionEvent e) {
            
        
           music();
        }
    }
    Last edited by Norm; 08-21-2011 at 11:09 PM. Reason: Added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    how can i solve this problem .
    What happens when you exit the program that is playing the music?

    Do the classes you are using have any methods for changing how it plays sound?

  3. #3
    ehsan is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    Hi . when close IDE sound repeating is cancel

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    It seems that there is no code to stop the sound from playing so it is not surpising that it continues to play.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    What happens when you exit the program that is playing the music?
    Does the music continue then?

  6. #6
    ehsan is offline Member
    Join Date
    Jul 2011
    Posts
    10
    Rep Power
    0

    Default

    when close netbean sound is stop

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    What happens when you exit/close the program that is playing the music?
    Not the IDE, the program that starts the music?

    Can you close the program that is playing the music and leave the IDE open?
    What happens if you close ONLY the program and leave the IDE open?

Similar Threads

  1. Java Sound
    By cyberia in forum Advanced Java
    Replies: 2
    Last Post: 08-19-2011, 01:58 PM
  2. Sound In java
    By chetoos in forum New To Java
    Replies: 2
    Last Post: 06-28-2011, 06:59 PM
  3. Problems with sound in java and USB sound card
    By marblecatdog in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 01:02 PM
  4. java sound
    By nikkka in forum New To Java
    Replies: 11
    Last Post: 04-10-2011, 03:54 PM
  5. Sound in applet Java
    By toby in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •