-1

So as the title suggests. I want to play a sound which is located in the .jar itself. Is this possible? and if not please let me know and then tell me how you would do it without having it in the .jar!

A sound in my case is a background song for a video game but also a sound effect for when you die, win or click on something etc..

EDIT:

So I have 2 questions. Question 1: How can I play sound using Java? Question 2: How can I do this from a sound located in my .jar

Thanks

  • Split your question into 2: "What do I need to Play any Audio in Java?" (Possible answer: "A InputStream to that Audioresource") and then "How can I open a InputStream to a file located in my jar?" – Felix Jun 13 '17 at 15:47

1 Answers1

0

Using this you may add sound and starting mp on appropriate action.

 final MediaPlayer mp = MediaPlayer.create(this, R.raw.file_name);

as mp.start();

Hope this helps. Or you may refer to this question on SO

Diksha
  • 406
  • 5
  • 20