java - First play of ogg file works, LineUnavailableException on second play -
i'm attempting loop ogg audiofiles in java. i'm using vorbisspi.
i able play file once. when try play file again, or play file,
lineunavailableexception: line format pcm_signed 44100.0 hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
i don't know i'm doing wrong.
method below.
public static void testline(file file) { try (audioinputstream in = audiosystem.getaudioinputstream(file)) { audioformat informat = in.getformat(); audioformat outformat = new audioformat(pcm_signed, informat.getsamplerate(), 16, informat.getchannels(), informat.getchannels() * 2, informat.getsamplerate(), false); info info = new info(sourcedataline.class, outformat); sourcedataline line = (sourcedataline) audiosystem.getline(info); if (line != null) { line.open(outformat); floatcontrol volume = (floatcontrol) line.getcontrol(floatcontrol.type.master_gain); volume.setvalue((float) ambiance.audio.track.default_volume); // stream line.start(); byte[] buffer = new byte[65536]; // magical? // yes: highest number can represented unsigned 16-bit binary number audioinputstream stream = audiosystem.getaudioinputstream(outformat,in); (int n = 0; n != -1; n = stream.read(buffer, 0, buffer.length)) { line.write(buffer, 0, n); } line.drain(); line.stop(); in.close(); retval = true; } } catch (unsupportedaudiofileexception|lineunavailableexception|ioexception e) { joptionpane.showmessagedialog(null, e.getmessage(), e.getclass().tostring(), joptionpane.error_message); } }
you need call close()
on line
when done it.
Comments
Post a Comment