AudioInputStream -- 'skip()' method seems not to work

T

tom arnall

I am using AudioInputStream and I find that the 'skip()' method seems not to
work. The thing 'executes' without a murmur, returning a value as if doing
the skip, but in fact nothing gets skipped. Code is:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.Vector;
import java.util.Enumeration;
import java.io.*;
import javax.sound.sampled.*;
import java.awt.font.*;
import java.text.*;

..
..
..
..

AudioFormat format = getFormat();
AudioInputStream playbackInputStream =
AudioSystem.getAudioInputStream(format, audioInputStream);

DataLine.Info info = new DataLine.Info(SourceDataLine.class,
format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line matching " + info + " not supported.");
return;
}

try {
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format, bufSize);
}

catch (LineUnavailableException ex) {
System.out.println("Unable to open the line: " + ex);
return;
}

int frameSizeInBytes = format.getFrameSize();
int bufferLengthInFrames = line.getBufferSize() / 8;
int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
byte[] data = new byte[bufferLengthInBytes];
int numBytesRead = 0;

// start the source data line
line.start();

int j = 0;
try {
!!!!!!HERE IS
SKIP!!!!!!!!System.out.println(""+playbackInputStream.skip(1000));
}
catch (Exception e) {
System.out.println(e);
}
while (j<1000) {
j++;
try {

if ((numBytesRead = playbackInputStream.read(data)) == -1) {
break;
}
int numBytesRemaining = numBytesRead;
while (numBytesRemaining > 0 ) {
numBytesRemaining -= line.write(data, 0, numBytesRemaining);
}
} catch (Exception e) {
System.out.println("Error during playback: " + e);
break;
}
}

thanks,

tom arnall
north spit, ca
 
A

Andrew Thompson

I am using AudioInputStream and I find that the 'skip()' method seems not to
work. The thing 'executes' without a murmur, returning a value as if doing
the skip, but in fact nothing gets skipped.

...and what?

Without compilable code, or a question, I
cannot see this thread going very well.

Andrew T.
 
T

tom arnall

Andrew said:
..and what?

Without compilable code, or a question, I
cannot see this thread going very well.

how about, 'why's it f'g up?'. anyway forget the post -- i found the
problem. i was not feeding a big enough number to the skip() method to make
its effect apparent. good point about the compilable code.

tom arnall
north spit, ca
usa
 
A

Andrew Thompson

how about, 'why's it f'g up?'.

Now that's more like it! But
avoiding swearwords, or swearword
abbreviations, is generally a good
idea for this technical group.

( Except when talking to multi-posting
spammers, then all bets are off! ;)
..anyway forget the post -- i found the
problem. i was not feeding a big enough number to the skip() method to make
its effect apparent.

Glad you sorted it.
..good point about the compilable code.

If looking to post code for any future
problem, I recommend* you have a look
over the article on the SSCCE first.
<http://www.physci.org/codes/sscce>

* Not that surprising, given I wrote it.

Andrew T.
 
T

tom arnall

Andrew said:
Now that's more like it! But
avoiding swearwords, or swearword
abbreviations, is generally a good
idea for this technical group.

( Except when talking to multi-posting
spammers, then all bets are off! ;)


Glad you sorted it.


If looking to post code for any future
problem, I recommend* you have a look
over the article on the SSCCE first.
<http://www.physci.org/codes/sscce>

* Not that surprising, given I wrote it.

Andrew T.

great stuff, the ssccee piece. i actually do this usually and more often
than not find that the preparation of the example makes the solution
obvious. totally forgot myself with the skip() thing.
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top