Getting an Audiostream to work in Java, Getting Malformed URL Exception
So I have this class which does not appear to work for whatever reason, it is giving me a Malformed URL exception but I can't find any reason the URL shouldn't b开发者_高级运维e valid.
public static void nyan()
{
String soundfile = "http://api.ning.com/files/3zmSvhA*3jKxFJj1I5uh5dp5oCynyyMksQjwS3JWWQNlriTzDzX61KtlFnuQtx-hEmV7NdqVgofmZvh7cXOX-UVJ47m1SR4a/nyanlooped.mp3";
URL url = new URL(soundfile);
AudioStream as = new AudioStream (url.openStream());
AudioData data = as.getData();
ContinuousAudioDataStream cas = new ContinuousAudioDataStream (data);
AudioPlayer.player.start(cas);
}
Any help would be appreciated, it's probably something simple, thanks
What version of Java are you using? I can very well create a URL from URL url = new URL(soundfile);
using Java 6. The URL is fine, it does not contain any unsafe characters, at least not the one that you posted here.
But here's my guess: The example you posted was not the one that really caused the error, could that be the case? Had a similar problem once - you are Base64-encoding binary data there to construct the URL. This works often, but not always: as soon as the encoding contains a +
you're likely to run into trouble, the +
would have to be URL-encoded.
精彩评论