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

Discussion in 'Java' started by tom arnall, Feb 10, 2007.

  1. tom arnall

    tom arnall Guest

    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


    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Feb 10, 2007
    #1
    1. Advertising

  2. Re: AudioInputStream -- 'skip()' method seems not to work

    On Feb 11, 8:13 am, tom arnall <> wrote:
    > 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.
    Andrew Thompson, Feb 11, 2007
    #2
    1. Advertising

  3. tom arnall

    tom arnall Guest

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

    Andrew Thompson wrote:

    > On Feb 11, 8:13 am, tom arnall <> wrote:
    >> 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.
    >


    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

    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Feb 11, 2007
    #3
  4. Re: AudioInputStream -- 'skip()' method seems not to work

    On Feb 12, 4:46 am, tom arnall <> wrote:
    > Andrew Thompson wrote:
    > > On Feb 11, 8:13 am, tom arnall <> wrote:
    > >> 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.

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

    >
    > 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.
    Andrew Thompson, Feb 11, 2007
    #4
  5. tom arnall

    tom arnall Guest

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

    Andrew Thompson wrote:

    > On Feb 12, 4:46 am, tom arnall <> wrote:
    >> Andrew Thompson wrote:
    >> > On Feb 11, 8:13 am, tom arnall <> wrote:
    >> >> 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.

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

    >>
    >> 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.


    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.



    --
    Posted via a free Usenet account from http://www.teranews.com
    tom arnall, Feb 11, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frederic Gignac

    Expiration date seems not to work

    Frederic Gignac, Jul 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    408
    Frederic Gignac
    Jul 8, 2003
  2. Wootaek Choi
    Replies:
    1
    Views:
    291
    Marshal Antony
    Feb 10, 2004
  3. Mosiuoa Tsietsi

    AudioInputStream byte data persistence

    Mosiuoa Tsietsi, Sep 15, 2003, in forum: Java
    Replies:
    0
    Views:
    406
    Mosiuoa Tsietsi
    Sep 15, 2003
  4. Ed Chen
    Replies:
    1
    Views:
    536
    Boudewijn Dijkstra
    May 27, 2004
  5. Eric Capps
    Replies:
    1
    Views:
    872
    Chris Uppal
    Jul 12, 2006
Loading...

Share This Page