Reputation: 21971
When I embed my resource and use the follwoing:
getClass().getResourceAsStream("sound.wav")
I get the following:
could not get audio input stream from input stream
If I link directly to the file it works fine.
Upvotes: 1
Views: 323
Reputation: 168795
If I link directly to the file it works fine.
It seems that you mean File
or URL
by that. (Can you confirm that & which one you mean, if so?) In that case, you'll often find that Java Sound requires a repositionable InputStream
, which is (strangely) not what getResourceAsStream()
returns.
The solution to that problem is to load the sound from URL
. Obtain the URL using something like:
URL urlToClip = this.getClass().getResource("sound.wav");
// sanity check!
System.out.println("urlToClip: " + urlToClip);
Upvotes: 2