Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:36:02+00:00 2026-06-16T05:36:02+00:00

I am working on a program that plays music in the background via multithreading,

  • 0

I am working on a program that plays music in the background via multithreading, because the GUI freezes up otherwise. I have a basic knowledge of multithreading (volatile, synchronizing, etc.) but I was wondering how to immediately stop/pause a thread (even when processes are processing). I have the music looping in the background but if I hook a stop variable up to the loop the song has to stop playing for the music to stop. So my question remains, from the parent thread is there any way to immediately pause or terminate the music in the middle of the song, because I have audio to play after it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:36:03+00:00Added an answer on June 16, 2026 at 5:36 am

    First, most loops in a thread should look similar to this:

    while(!isInterrupted()) {
        try {
           // do something (like play song)
        } catch (InterruptedException e) {
            interrupt();
        }
    }
    

    If there are blocking calls inside the loop (which it sounds like from your description), they likely allow interrupt(). A call to interrupt() from the outside of the thread will break the blocking call and dump you into the catch block. This ends up clearing the “interrupt” flag, so you need to call interrupt again to get out of the loop.

    Depending on how you’re playing music:

    • If you’re using a library that has a “pause” or “stop” method to play the music, you can just use that. Looks like you’re using jFugue – its player has a pause() method – have you tried calling that?
    • If you’re doing something else, you’ll need to keep track of the song’s position and call interrupt() on the thread. If you want to restart, you’ll need to seek back to the tracked position

    Note that if you want to restart with the above loop, you’ll need a nested loop such as:

    while(true) {
        while(!isInterrupted()) {
            ...
        }
    }
    

    If you only have the !isInterrupted() loop, the thread will finish, and cannot be restarted.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

working on making a flash program that loads about 1000 jpegs and then plays
I am working on a project that plays audio for part of the program.
I have a very old, very very large, fully working, C program which plays
I have spent many hours working on this program that is supposed to play
I have a working program written in Java with the Java Sound API that
I have a working program that could load and play a video file. It
I have a tic tac toe program and I've got everything working that way
I'm working on a program that will sort files based on extension I currently
I'm working on a program that reads in users input as a string, which
I'm working on a program that asks for input, then calculates and posts the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.