Music not playing in .JAR-file

Music not playing in .JAR-file

images not showing in jar file
jar file with image
how to get a path to a resource in a java jar file
how to package resources in jar
how to add sound to java game
java play sound
youtube ryisnow

I'm trying to make a song play when opening the .JAR-file. It works fine in Netbeans but when opening the .Jar-file only the button for scenechange and the images on those scenes show.

In the controller for the FXML i've initialized a Thread for playing the song:

@Override
public void initialize(URL url, ResourceBundle rb) {
    PlaySong ps = new PlaySong();
    Thread thread = new Thread(ps);
    thread.start();

} 

This calls the class with the thread which should play the song:

public class PlaySong implements Runnable {

@Override
public void run() {
    playSong();
}

static void playSong(){
    try{
        AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("/src/maanedsdag2/AssetsLibrary/James Smith  - Just the Way You Are.wav").getAbsoluteFile());
        Clip clip = AudioSystem.getClip();
        clip.open(audioInputStream);
        clip.start();

        Thread.sleep(clip.getMicrosecondLength()/1000);
    } catch(Exception e){

    }
}
}

My intent is to start playing the song when opening the FXML via the initialize method.

Hope you guys can help.


Your music file should be inside of the 'src' file of your project for being deployed in JAR. And you should use "getResourceAsStream()" to get your sound file.

How to Make a JAR File with Resources (Audio), In this video, we will use URL and make a JAR file that contains audio files. Category Duration: 10:34 Posted: Nov 5, 2017 I am using the JLayer MP3 Library to play an MP3 file in my program. My teacher told us to use something like: imageLabel = new JLabel(ImageIcon(this.getClass().getResource("filename.jpg"))); to load our music and images if we are going to export our programs as an executable .jar file.


When you launch your application from your IDE you can access to src file because your JVM execution Path is your project folder.

So you will understand that in a jar you don't have your project. In a Jar the execution path is the folder containing your jar and you will agree that even manually you don't found the folder src in this folder?

You need to consider your music track as resource and not as a file. I suggest you to read: Location-Independent Access to Resources.

But in your case:

SomeClass.class.getResourceAsStream("relativePathfromSomeClasstoyourwavFile");

[SOLVED] sound compiling problem, [SOLVED] sound compiling problem - sound doesn't play in jar - Java-Gaming.​org. (I'm not using the lwjgl b/c I didn't know about it when I started, but I'm give it the file location in my project (ex: playMusic(music/Title.au); ) Tech support scams are an industry-wide issue where scammers trick you into paying for unnecessary technical support services. You can help protect yourself from scammers by verifying that the contact is a Microsoft Agent or Microsoft Employee and that the phone number is an official Microsoft global customer service number.


Duplicate?

OS file systems do not "see" into jar files. Use a URL instead, which can.

It is common to use a relative addressing scheme, and to place the audio in a resources folder of some sort. But you can also just put the audio in the same file as the class that is calling it. Or reference the root of your project with an "absolute" address (address starts with char "/"). Your choice.

The "duplicate" tag above has code examples.

Music not working in compiled .jar, Music not working in compiled .jar - Java-Gaming.org. Are you sure you have your sound files in your .jar file once you compile them? Amazon Music comes with a feature where it blocks songs that contain explicit lyrics. So if you are trying to play such a song, it will not play if the explicit filter setting is enabled. To turn


*.wav music not played in deployed .jar · Issue #5254 · libgdx/libgdx , Music menuMusic = Gdx.audio.newMusic(Gdx.files.internal("audio/​menu_screen_loop.wav")); menuMusic.play(); <----- this does not work. Download Music for Offline Playback Using the iOS App. Download Music for Offline Playback Using the Android App. Download Music for Offline Playback Using Fire Tablet. Download Purchased Music Using a Web Browser. Download Purchased Music with Amazon Music for PC and Mac. Add Purchased Music to iTunes. Add Purchased Music to Windows Media Player.


[JavaFx] exported JAR file does not play sound. : learnprogramming, It works as intended when its run from Eclipse. But once I export the program into JAR file the alarm sound stops working. (because it can't find the mp3 file). Not sure if this is the right place to post this query but here goes: Bought new car (mercedes) has a usb connection in consul like most new cars have. Told I could put my music onto a stick and it will play..ha ha . I have downloaded itunes library and converted music into MP3 format as


Java sound example: How to play a sound file in Java , As you can see from that Java code, after I retrieve the sound file from my jar file, the process of playing the sound file is the same in this code  First, make sure that the audio you are trying to upload is of a supported format. Supported formats include MP3, AAC (.m4a), WMA, FLAC, OGG, ALAC (.m4a), and DRM protected AAC (.m4p). Some music file types like WAV are not supported. If songs aren’t uploading, make sure that the library isn’t full.