javax.sound.sampled - Random Access on AudioInputStream java -
is there example of randomly accessing audioinputstream? ordinary audio player - when take bar wherever want , plays wherever want, how can access bytes in audio stream in manner?
something simple : read(byte[] buffer, long startingfrom) startingfrom can wherever want in audio stream
using (simulating?) random access in audioinputstream same in normal inputstream. can create mark() @ beginning of file, before calls read() have been done. then, when want random access, stop reading stream, go marker position calling reset() , use skip() go location desire.
note initial 'mark' default 0 audioinputstream, initial call not needed. behavior not specified might change in future.
the implementation of audioinputstream (oracle java 8) supports mechanism if underlying stream (for instance inputstream give constructor) supports it. can find if audioinputstream supports calling marksupported().
unfortunately when using utility functions audiosystem create audioinputstream can't influence underlying stream. differ per platform. if stream not support (or want absolutely sure support it) create new audioinputstream wrapping 1 in bufferedinputstream. example this:
audioinputstream normalstream = audiosystem.getaudioinputstream(...); audioinputstream bufferedstream = new audioinputstream(new bufferedinputstream(normalstream), normalstream.getformat(), audiosystem.not_specified); disclaimer: qualify has 'hack' create random access. to surprise find little simulating random access using mark/reset mechanism in edit: john skeet agrees me on approach.inputstream. might because there caveat it.
Comments
Post a Comment