java - Conflicting Jar Methods -
i have been trying make first gui music player in java. far have been able play mp3 javasound , mp3spi. now, want support .m4a songs , have researched best library jaad. downloaded it, added project , worked when tried play .m4a song. problem happens when try play .mp3 after adding jaad library. code playing songs is:
file file = new file(pathtosong); audioinputstream audiostream= audiosystem.getaudioinputstream(file); // obtains audio input stream of song audioformat baseformat = audiostream.getformat(); //obtains audio format of song in audio input stream. decodedformat = new audioformat(audioformat.encoding.pcm_signed, //the type of encoding audio stream baseformat.getsamplerate(), //sample rate of audio stream 16, //number of bits in each sample of sound has format. baseformat.getchannels(), //number of audio channels in audio stream baseformat.getchannels() * 2, //number of bytes in each frame of audiostream baseformat.getsamplerate(), //number of frames played or recorded per second, sound in audio stream false); //data stored in little-endian order decodedaudiostream = audiosystem.getaudioinputstream(decodedformat, audiostream); //obtains audio input stream of indicated encoding converting provided audio input stream. playsong(); //play song
(playsong() read stream , writes bytes sourcedataline)
the error when try play .mp3 after adding jaad library following:
java.io.ioexception: resetting invalid mark @ java.io.bufferedinputstream.reset(bufferedinputstream.java:416) @ net.sourceforge.jaad.spi.javasound.aacaudiofilereader.getaudioinputstream(aacaudiofilereader.java:118) @ net.sourceforge.jaad.spi.javasound.aacaudiofilereader.getaudioinputstream(aacaudiofilereader.java:143) @ javax.sound.sampled.audiosystem.getaudioinputstream(audiosystem.java:1162) @ song.run(song.java:38)
from understanding, seems getaudioinputstream javasound , jaad conflicting. how can resolve conflict?
well found solution using mp3spi , jaad alongside each other based on berry150's code in answer here: jaad stopping other providers working. first, have order jars in classpath jlayer, mp3spi , tritonous share loaded before jaad. getting audioinputstream, use following code:
if (getaudioformat().equals(".mp3")) { audiostream = audiosystem.getaudioinputstream(file); // obtains audio input stream of song } else if (getaudioformat().equals(".m4a")){ audiostream = new aacaudiofilereader().getaudioinputstream(file); }
so happens if audio mp3, getaudiostreammethod() javasound called first since jar loaded first. if audio .m4a, new instance of accaudiofilereader() created , getaudioinputstream() of jaad library called.
Comments
Post a Comment