Thank you so much! I've been trying to get audio to work via an executable jar, but I guess executable jars run much different than exporting as a normal jar.. You're a life saver
Hello Ryi. So after watching it video like ten times, I followed everything I said perfectly. But when I run my program, an error message pops up saying: Java.lang.NullPointerException. It points at the clip.setFramePosition(0); And mu14.play( ); as the reason for not working.....my code is this...which I got from you....It's not letting me create a jar file with the audio public class Music { Clip clip; public void setURL(URL sound filename) { try { AudioInputStream sound = AudioSystem.getAudioInputStream(sound filename); clip = AudioSystem.getClip( ); clip.open(sound); } catch (Exception e) { } } public void play( ) { clip.setFramePosition(0); //it points error at this line Ryi. clip.start( ); } Public class Title screen handler implements Action Listener{ public void actionPerformed (ActionEvent event) { String (your choice) { case "start": mu13.setURL(sound URL); mu13.play( ); //error points here too.. start button.setVisible(false); mainMenuScreen("start"); break; } }
Hi. Could you please Help. I have exported one Jar File. In eclipse i have a Source Directory Named (Configuration). When i execute the application in Eclipse i can have access to the file located in /configuration/config.properties File propertieFile = new File(getClass().getClassLoader().getResource("configuration/config.properties").getFile()); Then i make a Test if(propertieFile.exists(){ System.out.println("exists");} My Problem is this works on Eclipse. but when i export my Project in .jar File and execute the Jar File it does not work anymore. How do i pass a new File to the File Class for checking is exists when the Project ist exported in Jar File? I have try with URL .toUri many things. I Walk aroud the Google and i dont find yet a solution. I need to check if this file exists in the Resource Folder named configuration and if not to have the chance to create the Properties File. Having a reference from File class. Very important i dont use Marven or Spring. Is really crazy sometimes the Project looks good in Eclipse and by exporting the Jar File the change the structure. You would help me really too much i you have a solution for this problem. i am studying Java and i dont want to give up. Thanks.
hey i was using the sound effect video and implemented it into my RPG game, i came across a slight problem. When i want to make it so both the title screen button plays a sound effect and also take me to the next screen. do you know how this could be done
I'm not sure how you constructed your code but basically you can add se.setURL(clickSoundURL); se.play(); to your actionPerformed method like this: public void actionPerformed(ActionEvent event){ se.setURL(clickSoundURL); se.play(); createGameScreen(); }
Very helpful! Thanks!
And if the getResource method doesn't work, try using "/" forward slash before file name. ex. ("/audio.wav"). That's how it worked for me.
Love you
Thank you! 🙇
Thank you so much! I've been trying to get audio to work via an executable jar, but I guess executable jars run much different than exporting as a normal jar.. You're a life saver
Thank you sir! I'm just starting out, and this is at least the second video of yours that has helped me with my project.
Glad I could help! Thank you for the comment!
Worked like a charm! thanks a bunch
That exactly what i want ! Thank you
thank u mate!
Thanks man you are angel!
Hello Ryi.
So after watching it video like ten times, I followed everything I said perfectly. But when I run my program, an error message pops up saying: Java.lang.NullPointerException.
It points at the clip.setFramePosition(0);
And
mu14.play( ); as the reason for not working.....my code is this...which I got from you....It's not letting me create a jar file with the audio
public class Music {
Clip clip;
public void setURL(URL sound filename) {
try {
AudioInputStream sound = AudioSystem.getAudioInputStream(sound filename);
clip = AudioSystem.getClip( );
clip.open(sound);
} catch (Exception e) {
}
}
public void play( ) {
clip.setFramePosition(0); //it points error at this line Ryi.
clip.start( );
}
Public class Title screen handler implements Action Listener{
public void actionPerformed (ActionEvent event) {
String (your choice) {
case "start":
mu13.setURL(sound URL);
mu13.play( ); //error points here too..
start button.setVisible(false);
mainMenuScreen("start");
break;
}
}
did you manage to fix it dude? I'm having a similar issue when I try to export my game as a JAR
Your awesome!!
I want to see a gun firing through sound effects.
Very helpful, thanks very much for this.
You're welcome!
Thanks!
Hi. Could you please Help. I have exported one Jar File. In eclipse i have a Source Directory Named (Configuration). When i execute the application in Eclipse i can have access to the file located in /configuration/config.properties File propertieFile = new File(getClass().getClassLoader().getResource("configuration/config.properties").getFile()); Then i make a Test if(propertieFile.exists(){ System.out.println("exists");}
My Problem is this works on Eclipse. but when i export my Project in .jar File and execute the Jar File it does not work anymore.
How do i pass a new File to the File Class for checking is exists when the Project ist exported in Jar File? I have try with URL .toUri many things. I Walk aroud the Google and i dont find yet a solution. I need to check if this file exists in the Resource Folder named configuration and if not to have the chance to create the Properties File. Having a reference from File class.
Very important i dont use Marven or Spring.
Is really crazy sometimes the Project looks good in Eclipse and by exporting the Jar File the change the structure.
You would help me really too much i you have a solution for this problem. i am studying Java and i dont want to give up.
Thanks.
hey RyiSnow, will this code work if we move the jar file to another system or delete the audio from the res folder?? THANK YOU SO MUCH BTW!!!
Yes the jar file should work as long as you packed the audio file into the file and the targeted system has appropriate version of Java.
@@RyiSnow thank you so much for helping!
I am finding axactly. What you doin in this video
So you use github ??
hey i was using the sound effect video and implemented it into my RPG game, i came across a slight problem. When i want to make it so both the title screen button plays a sound effect and also take me to the next screen. do you know how this could be done
Also if possible how can you adapt it to full screen?
I'm not sure how you constructed your code but basically you can add
se.setURL(clickSoundURL);
se.play();
to your actionPerformed method like this:
public void actionPerformed(ActionEvent event){
se.setURL(clickSoundURL);
se.play();
createGameScreen();
}
RyiSnow thank you so much, keep doing what you do, you are very good at demonstrating and explaining java. It has helped me so much!
Glad to hear that!
thanks a lot!
Hey, I try to recreate your stuff and was working on it for like 3h, can U please upload this code to some webside or send it to me?
Does anyone know how to do this in IntelliJ?
I love you
Ummm I had some code already I don't think I can change it.... Is it possible?? Here is the Pastebin pastebin.com/g09zBsrL