Best way to do this

F

Fran Garcia

I´m developping an applet that plays a wav file and now I wanna add a
slider to showing the position for the wav file, but I have no idea to
do it. How can I communicate the read for the wav file and the slider.
Listener, Timer or what?

Thanks in advance

Fran García
 
C

Chris Smith

Fran Garcia said:
I=3Fm developping an applet that plays a wav file and now I wanna add a
slider to showing the position for the wav file, but I have no idea to
do it. How can I communicate the read for the wav file and the slider.
Listener, Timer or what?

Are you using the java.applet.AudioClip interface, or
javax.sound.sampled.*? If the former, you're not on solid ground trying
to stretch the functionality this far. You could probably kludge
something together using a custom URLStreamHandler for your URL and
wrapping the resulting InputStream to count the progress and report
it... but that would be fairly ugly (also, I'm unsure if common browsers
grant NetPermission("specifyStreamHandler"), which would be needed).

If you're using javax.sound.sampled.* then this is easier. Post some
code to play the sound, and I can help you get the progress meter going.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
F

Fran Garcia

I send you some code:

This is the code for the creation of the class to playing the wav
file.

public SimpleAudioPlay(String fileName,int tamano)
{
m_tamanoBuffer=tamano;
m_nombreFich=fileName;
m_ficheroWav=new File(m_nombreFich);
try {
m_flujoEntradaAudio =
AudioSystem.getAudioInputStream(
m_ficheroWav);
}
catch (IOException ex) {
System.err.println("ERROR : "+ex.getMessage());
}
catch (UnsupportedAudioFileException e) {
System.err.println("ERROR : "+e.getMessage());
}
try {
m_formatoAudio = m_flujoEntradaAudio.getFormat();
DataLine.Info info = new
DataLine.Info(SourceDataLine.class,m_formatoAudio);
m_line = (SourceDataLine) AudioSystem.getLine(info);
}
catch (LineUnavailableException ex1) {
System.err.println("ERROR : "+ex1.getMessage());
}
try {
m_line.open(m_formatoAudio);
}
catch (LineUnavailableException ex2) {
System.err.println("ERROR :
"+ex2.getMessage());
}
catch (Exception ex) {
System.err.println("ERROR : "+ex.getMessage());
}

}

And then I must do m_line.start() in the root class. Do you understand
me?

I hope that you can help me!
 
C

Chris Smith

Fran Garcia said:
This is the code for the creation of the class to playing the wav
file.

Okay, so you're doing playback with the javax.sound.sampled.* package.
That's good, and makes things a lot easier. Now you just need to
communicate your position to the the JSlider. Somewhere, do you have a
loop that looks something like this?

byte[] buffer = new byte[BUF_SIZE];
int len;
while ((len = m_flujoEntradaAudio.read(buffer)) != -1)
{
m_line.write(buffer, 0, len);
}

If so, then you just need to add code inside that loop to update the
JSlider position.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
F

Fran Garcia

Yes I have exactly what you have written but I have this in another
class to the applet.

I have an applet class FRECYPLAY.class and then I have a class with
the definition for the plays methods. Do you understand me? How can I
access to the methods for the JSlider?

Thanks another time!!!

Fran García


Chris Smith said:
Fran Garcia said:
This is the code for the creation of the class to playing the wav
file.

Okay, so you're doing playback with the javax.sound.sampled.* package.
That's good, and makes things a lot easier. Now you just need to
communicate your position to the the JSlider. Somewhere, do you have a
loop that looks something like this?

byte[] buffer = new byte[BUF_SIZE];
int len;
while ((len = m_flujoEntradaAudio.read(buffer)) != -1)
{
m_line.write(buffer, 0, len);
}

If so, then you just need to add code inside that loop to update the
JSlider position.
 
F

Fran Garcia

I have tested to do the jSlider as static. I know that isn´t the
better solution, but I have tested and I noticed that the effect
doesnt´s semm well. I wanna make every second, update the jslider with
the information from the class that plays the wav file. Do you
understand me?

Something like:

every second do{
update_jSlider(ClassPlay(getFramePosition));
}

How do you see it?

Thanks

Fran García

Chris Smith said:
Fran Garcia said:
This is the code for the creation of the class to playing the wav
file.

Okay, so you're doing playback with the javax.sound.sampled.* package.
That's good, and makes things a lot easier. Now you just need to
communicate your position to the the JSlider. Somewhere, do you have a
loop that looks something like this?

byte[] buffer = new byte[BUF_SIZE];
int len;
while ((len = m_flujoEntradaAudio.read(buffer)) != -1)
{
m_line.write(buffer, 0, len);
}

If so, then you just need to add code inside that loop to update the
JSlider position.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top