How to start an audio automatically on startup of a Java application?

Asked

Viewed 53 times

1

I am having difficulty starting this application along with an audio "Mixx.mp3". I have no errors, but the sound does not play.

public class MostrarLuta {

    URL som = MostrarLuta.class.getResource("mixx.mp3");
    AudioClip Som = Applet.newAudioClip(som);

    public static void main(String[] args) {
        TelaInicial telaInicial = new TelaInicial();
        telaInicial.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //telaInicial.setSize(1366, 768); // tamanho da tela
        telaInicial.setLocationRelativeTo(null); // centraliza o JFrame
        telaInicial.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
        telaInicial.setVisible(true);

        MostrarLuta music = new MostrarLuta();
        System.out.println(music.som);
        System.out.println("\n"+music.Som);
        music.Som.play();
    }
}

1 answer

0


Dude, I was making a java desktop application that needed to perform sound in mp3, wav, etc. At first I tried to use this class you’re using, Audioclip, but without success. The problem as it seems is not code but the fact that it is not an applet (I believe it is the same with this project of yours. Are you creating an applet?). They’re changing the project to use Jlayer (http://www.javazoom.net/javalayer/javalayer.html) . Jlayer is a library to run audio files. This worked cool.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.