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 6969241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:33:22+00:00 2026-05-27T16:33:22+00:00

I have a Runnable that gets a line to the Mic, reads from it

  • 0

I have a Runnable that gets a line to the Mic, reads from it and stores it in an OutputStream.
When I start the 1st instance of this thread it works.
After 1st thread completes (exists run() method) i start another instance of the thread but this time i get:

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 8 bit, stereo, 2 bytes/frame,  not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)

My thread looks like this:

public void run() {
     float sampleRate = 44100.00F;
        //8000,11025,16000,22050,44100
        int sampleSizeInBits = 8;
        //8,16
        int channels = 2;
        //1,2
        boolean signed = true;
        //true,false
        boolean bigEndian = false;
        //true,false
    AudioFormat format = new AudioFormat(sampleRate,
           sampleSizeInBits,
           channels,
           signed,
           bigEndian);

    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); // format is an AudioFormat object

    // Obtain and open the line.
    try {
        targetLine = (TargetDataLine) AudioSystem.getLine(info);
        targetLine.open(format); //exception is throw here
        targetLine.start();
        ByteArrayOutputStream out  = new ByteArrayOutputStream();
        CountingOutputStream countingOutStream = new CountingOutputStream(out);
        int numBytesRead;
        byte[] data = new byte[targetLine.getBufferSize() / 5];

        File binFile = new File("C:\\audio\\random4.txt");
        FileOutputStream fr = new FileOutputStream(binFile);


        while ( (countingOutStream.getCount()/1024) < targetSizeKB) {
           numBytesRead =  targetLine.read(data, 0, data.length);
           countingOutStream.write(data, 0, numBytesRead);
        }    




        fr.write(newByte,0,ii);
        countingOutStream.close();
        fr.close();

       targetLine.flush();
        targetLine.stop();
        targetLine = null;
}
  • 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-05-27T16:33:23+00:00Added an answer on May 27, 2026 at 4:33 pm

    You’re calling flush and stop on targetLine, but you don’t call close – I suspect you need to do that in order to release it properly. (It’s not clear why targetLine is an instance variable, by the way – does it need to be?)

    You should also be doing all the clean-up in finally blocks, so that the streams get closed even if an exception is thrown.

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

Sidebar

Related Questions

I have the following code in a Runnable that gets passed to a thread
I have created a Handler instance in the main ui thread(mUIHandler) and from a
I have this ActionListener that gets called in the EDT. My plot() function is
Consider that I have a main Thread which executes a new Runnable in a
I have a standalone Java application that gets data from a database and displays
Suppose I have a Runnable that does a simple file writing operation, and this
I have a Service that downloads a file from the internet. What I want
I have the following in my main activity: private void attemptLogin() { this.runOnUiThread(new Runnable()
I have started writing an application that gets in a certain website and gets
I have a basic asynchronous task that performs a web request. The thread is

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.