I'm playing an audio file using jlGui's BasicPlayer (it's based on Javasound).
The file is in a Samba share and I'm using Jcifs to access it. It gives me an InputStream
.
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( ... );
SmbFile f = new SmbFile( ... );
SmbFileInputStream audioIn = new SmbFileInputStream(f);
int bufSize = 8096;//should I use f.length() here?
audioBIS = new BufferedInputStream(audioIn, bufSize);
audioBIS.mark(f.length());
//call BasicPlayer
play(audioBIS);
I need to be able to position the pointer anywhere in the file, just like any common player.
The only solution I could think of was to use a BufferedInputStream
and a combination of mark/reset/skip everytime I need to reposition the pointer.
As soon as I open the file and get the Stream, I call the mark()
method, so that a subsequent reset()
will reposition me at the beginning. Then with skip()
I can go where I want.
audioBIS.reset();
audioBIS.skip(newBytePosition);
My problem is that the skip() call works as desired only if I specify a buffer big enough to contain the whole file.
Is there a more efficient way to do this?