Sign in to follow this  
Sean77771

Java play music from website?

Recommended Posts

Hi all. I have a mid file posted in the same directory as my java appplet on my website. How do I access that file from my java program? Right now I have this: try { URL url = new URL("http://seanstetris.50megs.com/"); tetris1 = getAudioClip(new URL(url, "tetris1.mid")); tetris2 = getAudioClip(new URL(url, "tetris2.mid")); tetris3 = getAudioClip(new URL(url, "tetris3.mid")); } catch(Exception e) { System.out.println("Error - files not loaded"); } but every time, it prints out the error message and when it tries to play the music I get a nullPointerException. Please help. Thanks.

Share this post


Link to post
Share on other sites
I have done what your asking (loading from the url), but I don't have the source with me at work. I believe when I did it, I used getCodeBase() to get the proper URL from the Applet extended class. maybe something like

AudioClip SomeAudio = getAudioClip( new URL( getCodeBase(), "tetris1.mid") );

You could always load it from the jar file:

InputStream = getClass().getResourceAsStream( "/tetris1.mid" );

hope that helps,

tHom

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this