Jump to content
  • Advertisement
Sign in to follow this  
Sean77771

Java play music from website?

This topic is 4182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!