Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stopping a looping javax.sound.sampled audio clip

 
Al Dunne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm fairly new to this so I hope I've posted this to the correct place.

I'm completing a project where a user gets to press a few buttons and they will see a waveform change and hear the amplitude of a sound increase or decrease. To get the sounds to play I'm using javax.sound.sampled.*

My code is as follows (the buttons the user presses are in a seperate GUI built class):-



The actual sounds are 10 seconds long so I want them to loop continuously until the user either increases or decreases the amplitude.

All my code is working fine. However, the problem I'm having is that everytime the user clicks the increase amplitude button and calls the playSound method, a new audio line gets opened and the sounds play at the same time.

Is there a way I can close all existing audio lines before a new one is opened? I've been looking for a couple of hours now but am getting more and more frustrated/confused.

Any help would be much appreciated.

Al.


 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch! Your question looks like it will required specific expertise in the javax.sound API, so I'll move it to Other JSE/JEE APIs. I'm sure someone will be along to answer it soon.
 
Al Dunne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks Greg.
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm misunderstanding something, but if you wanted to stop a Clip, why wouldn't you just call its "stop" method?
 
Al Dunne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

I'm fairly new to this so I was getting confused about where I should call the stop method. I had it in a few places but it wasn't working. I really don't understand about Clips etc yet.

I got the solution on another website yesterday afternoon. It was to put the following code before the try-catch in the playSound method.



Thanks for your reply though.

Al.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic