Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2008, 08:52 PM
BruenorBH's Avatar
Member
 
Join Date: Jan 2008
Location: Buffalo, NY
Posts: 14
Rep Power: 0
BruenorBH is on a distinguished road
Send a message via Yahoo to BruenorBH
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:

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."
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-07-2008, 10:22 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-08-2008, 12:58 AM
BruenorBH's Avatar
Member
 
Join Date: Jan 2008
Location: Buffalo, NY
Posts: 14
Rep Power: 0
BruenorBH is on a distinguished road
Send a message via Yahoo to BruenorBH
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."
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-08-2008, 02:53 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
Default
Yes, it could do that.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 06:15 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org