简体   繁体   中英

Java jLayer GUI Application freezes while playing the music

I'm working on a Java project that requires background music so I'm using jLayer (MP3 library for the Java Platform) for better applicability and performance for my project.

I need to play the music with the help of JFileChooser so that the user can easily run own music from the menu bar.

But the whole GUI application freezes whenever I'm trying to run the any random music.

Here's the code snippet of my Application

This is the Image of the Menubar where "Choose your own Music" is added as the Menu Item

Can anyone please help me fixing me this code?

The whole GUI application freezes whenever i'm trying to run the any random Music from the menu bar with the help of "JFileChooser"

Code executed from a listener is executed on the Event Dispatch Thread (EDT) . This Thread is responsible for responding to events and repainting the GUI. If you execute a long task (like playing music) then the GUI can't respond to events.

You need to start your music player on a separate Thread . One way to do this is to use a SwingWorker which provides additional functionality which is helpful when using Swing.

Read the tutorial on Concurrency in Swing for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM