Results 1 to 4 of 4
  1. #1
    BruenorBH's Avatar
    BruenorBH is offline Member
    Join Date
    Jan 2008
    Location
    Buffalo, NY
    Posts
    14
    Rep Power
    0

    Default Play wav file of users choice when an action is performed..

    I am trying to add audio to a break clock and I have been trying to figure it out.. I want the user to select the audio file (wav or midi) when clicking the audio button then when the action happens (like an alarm) the audio file plays once.

    Here is my code:

    Java Code:
    AudioClip song;
    File fileName = null;
    
    private AudioButtonHandler abHandler;
    
    JButton cmdAudio = new JButton("Audio");
    abHandler = new AudioButtonHandler();
    cmdAudio.addActionListener(abHandler);
    panel.add(cmdAudio);
    
    public class AudioButtonHandler implements ActionListener
    {
      {
        JFileChooser fc = new JFileChooser();
        int result = fc.showOpenDialog(null);
        if (result == JFileChooser.APPROVE_OPTION && result == JFileChooser.FILES_ONLY)
        {
          fileName = fc.getSelectedFile();
        }
      }
    }
    
    public class Sound
    {
      private URL songPath;
      
      Sound(File fileName)
      {
        try
        {
          songPath = fileName.toURL();
          song = AppletnewAudioClip(songPath);
        }
        catch(Exception e)
        {
        }
      }
    }
    also I was using song.play(); as the call but it made the clock stop after activating the pop-up message..
    "I do know everything, just not all at once. It's a virtual memory problem."

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

    Default

    I asssume that your problem is that the clock stops.

    To do two things at the same time, use threads.

    Put the song.play() code on its own thread.

  3. #3
    BruenorBH's Avatar
    BruenorBH is offline Member
    Join Date
    Jan 2008
    Location
    Buffalo, NY
    Posts
    14
    Rep Power
    0

    Default

    But the other issue is will this code save the path and file of the selected song then play it?
    "I do know everything, just not all at once. It's a virtual memory problem."

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,271
    Rep Power
    25

Similar Threads

  1. play vedio file and flash file in swing
    By rajasekharreddym in forum AWT / Swing
    Replies: 1
    Last Post: 07-30-2008, 08:22 PM
  2. how can I play an mp3 file in java?
    By iliana in forum Networking
    Replies: 1
    Last Post: 05-30-2008, 07:32 PM
  3. Need help with T/F and Multiple Choice
    By sayso36 in forum Advanced Java
    Replies: 0
    Last Post: 03-12-2008, 04:39 PM
  4. Adding file contents to Choice component
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-07-2008, 09:06 AM
  5. JXTaskPane Action performed
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 0
    Last Post: 12-10-2007, 01:27 PM

Posting Permissions

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