Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (623)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
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 2485 times)
0 Members and 1 Guest are viewing this topic.
Offline Funkymonk

Junior Newbie

« Posted 2007-07-18 20: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 Devvie

« Reply #1 - Posted 2007-07-18 22:09:33 »

quote from:

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 Devvie

« Reply #2 - Posted 2007-07-18 22: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 @
on /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 Devvie

« Reply #3 - Posted 2007-07-18 23: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 Devvie

« Reply #4 - Posted 2007-07-19 00: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 @
on /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline erikd

JGO Ninja

Medals: 16
Projects: 4
Exp: 14 years


« Reply #5 - Posted 2007-07-19 14: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.

KaiHH (6 views)
2015-10-06 20:22:20

KaiHH (11 views)
2015-10-06 19:41:59

BurntPizza (17 views)
2015-10-06 19:04:48

basil_ (44 views)
2015-09-30 17:04:40

shadowstryker (22 views)
2015-09-29 15:55:06

TheSpaceHedgehog (28 views)
2015-09-29 01:58:48

GamerC4 (54 views)
2015-09-24 21:10:38

GamerC4 (71 views)
2015-09-24 21:09:48

htuy (28 views)
2015-09-24 04:57:24

htuy (38 views)
2015-09-24 04:56:35
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 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‑
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!