• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Stopping a looping javax.sound.sampled audio clip

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks Greg.
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic