Exemple #1
0
 protected void closeLine(boolean willReopen) {
   CaptureThread oldThread = null;
   synchronized (this) {
     if (!willReopen && thread != null) {
       thread.terminate();
     }
     super.closeLine(willReopen);
     if (!willReopen) {
       if (ais != null) {
         if (VERBOSE) out("AudioCapture.closeLine(): closing input stream");
         try {
           ais.close();
         } catch (IOException ignored) {
         }
       }
       if (thread != null) {
         if (outputStream != null) {
           try {
             outputStream.close();
           } catch (IOException ignored) {
           }
           outputStream = null;
         }
         oldThread = thread;
       }
     }
   }
   if (oldThread != null) {
     if (VERBOSE) out("AudioCapture.closeLine(): closing thread, waiting for it to die");
     oldThread.waitFor();
     if (VERBOSE) out("AudioCapture.closeLine(): thread closed");
   }
 }
Exemple #2
0
 public void run() {
   byte[] buffer = new byte[getBufferSize()];
   if (VERBOSE) out("Start AudioCapture push thread");
   try {
     AudioInputStream localAIS = ais;
     while (!doTerminate) {
       out("Capture running");
       if (localAIS != null) {
         int r = localAIS.read(buffer, 0, buffer.length);
         if (r > 0) {
           synchronized (AudioCapture.this) {
             if (outputStream != null) {
               outputStream.write(buffer, 0, r);
               out("Recorded " + r + " Bytes");
               // _fireAudioCapturedEvent();
             }
           }
           if (outputStream == null) {
             synchronized (this) {
               this.wait(100);
             }
           }
         } else {
           if (r == 0) {
             synchronized (this) {
               this.wait(20);
             }
           }
         }
       } else {
         synchronized (this) {
           this.wait(50);
         }
       }
     }
   } catch (IOException ioe) {
     // if (VERBOSE) ioe.printStackTrace();
   } catch (InterruptedException ie) {
     if (DEBUG) ie.printStackTrace();
   }
   terminated = true;
   if (VERBOSE) out("Stop AudioCapture push thread");
 }