Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2008, 10:52 PM
BruenorBH's Avatar
Member
 
Join Date: Jan 2008
Location: Buffalo, NY
Posts: 14
BruenorBH is on a distinguished road
Send a message via Yahoo to BruenorBH
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
Sponsored Links
  #2 (permalink)  
Old 08-08-2008, 12:22 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
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, 02:58 AM
BruenorBH's Avatar
Member
 
Join Date: Jan 2008
Location: Buffalo, NY
Posts: 14
BruenorBH is on a distinguished road
Send a message via Yahoo to BruenorBH
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, 04:53 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Yes, it could do that.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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 10:22 PM
how can I play an mp3 file in java? iliana Networking 1 05-30-2008 09:32 PM
Need help with T/F and Multiple Choice sayso36 Advanced Java 0 03-12-2008 06:39 PM
Adding file contents to Choice component Java Tip Java Tips 0 02-07-2008 11:06 AM
JXTaskPane Action performed Rama Koti Reddy AWT / Swing 0 12-10-2007 03:27 PM


All times are GMT +3. The time now is 04:55 PM.


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