Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need to pause key listener  (Read 1912 times)
0 Members and 1 Guest are viewing this topic.
Offline Funkymonk

Junior Newbie





« Posted 2007-07-18 22:27:46 »

I am making an game and when a player attacks, I want to play a sound. I am stuck trying to pause the key listener while the sound is being played. This is what I want to do...
if player attacks, play sound,
if a key is pressed check if sound is playing, if not then execute...
... but I can't find any methods to check if the sound is playing. I tried just pausing the thread for the length of the sound but it doesn't pause the key listener and just seems like poor coding.
I am using AudioClip to load and play the sound.
Any advice would be greatly appreciated.
Offline Kova

Senior Member





« Reply #1 - Posted 2007-07-19 00:09:33 »

quote from: http://www.onjava.com/pub/a/onjava/excerpt/jenut3_ch17/index.html

Quote
But this highlights one of the shortcomings of the AudioClip interface: it allows you to play( ), stop( ), or loop( ) a sound, but it provides no way to track the progress of the sound or find out when it has finished playing. To achieve that level of control over the playback of sound, we need to use the JavaSound API, which we'll consider in the next section.

so as soon as I saw that I stopped, you can find the answer there...
Offline broumbroum

Junior Member





« Reply #2 - Posted 2007-07-19 00:33:04 »

KeyListener may be replaced by a KeyEventDispatcher used in common with the currentKeyboardEventDispatcher that you can find in the KeyboardFocusManager static method getCurrentKeyboardFocusManager() . Thus you will be able to make the manager to pause for a while because the Thread is single when it calls back the registered dispatchers. Smiley I use it though I'm having problems to get it synchronized with the whole stuff for the moment...

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Member





« Reply #3 - Posted 2007-07-19 01:36:26 »

still, it doesn't solve his major problem... and that is to cleanly learn is a certain sound playing or not. I think it's better to focus on that then doing workarounds. Funkymonk, if you pause keylistener thread then it will be unresponsive for other actions also, and you will be stuck with one action until sound stops playing.
Offline broumbroum

Junior Member





« Reply #4 - Posted 2007-07-19 02:14:41 »

well that's a bit fuzzy to pause the keyboard.... My method involves launching swing timers and reading from one synchronized Stack of KeyEvents caught by the dispatcher, that avoids "pausing" the dispatcher.
Moreover about the audio,  it'd be "thinkable" to use Thread-locking on your sound clip launched from dispatcher while it is playing. Of course the problem is to monitor the sound target, which is unknown to me.

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2007-07-19 16:45:03 »

I'm using javax.sound.sampled.Clip and use it's isActive() method to check if the sound is playing.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (12 views)
2014-07-29 12:09:19

Riven (8 views)
2014-07-29 12:08:52

Dwinin (9 views)
2014-07-29 04:59:34

E.R. Fleming (25 views)
2014-07-28 21:07:13

E.R. Fleming (10 views)
2014-07-28 21:06:25

pw (39 views)
2014-07-23 19:59:36

Riven (39 views)
2014-07-23 15:16:32

Riven (27 views)
2014-07-23 15:07:15

Riven (28 views)
2014-07-23 14:56:16

ctomni231 (59 views)
2014-07-18 00:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!