Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning an InputStream into a SeekableByteChannel

Tags:

java

openal

I am attempting to convert an InputStream to a SeekableByteChannel in order to stream in Open AL with LWJGL.

The current code is as follows thanks to the help of a demo online:

InputStream source = Thread.currentThread().
                         getContextClassLoader().
                         getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source);

But I'm not sure, if at all possible, how I can seek through the OGG file in order to stream without converting it to a SeekableByteChannel

I'd be glad to supply more code if needed and thanks for any help in advance

like image 257
Alec French Avatar asked Oct 27 '25 08:10

Alec French


1 Answers

Take a look at apache commons compress library, you can construct a SeekableInMemoryByteChannel from byte array. And convert InputStream to byte array is very easy also.

InputStream inputStream; // input stream
SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel
       (IOUtils.toByteArray(inputStream));
like image 192
alijandro Avatar answered Oct 29 '25 22:10

alijandro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!