public synchronized void start(boolean loop) {
   if (DEBUG || Printer.debug) Printer.debug("> DataPusher.start(loop=" + loop + ")");
   try {
     if (threadState == STATE_STOPPING) {
       // wait that the thread has finished stopping
       if (DEBUG || Printer.trace) Printer.trace("DataPusher.start(): calling stop()");
       stop();
     }
     looping = loop;
     newPos = 0;
     wantedState = STATE_PLAYING;
     if (!source.isOpen()) {
       if (DEBUG || Printer.trace) Printer.trace("DataPusher: source.open()");
       source.open(format);
     }
     if (DEBUG || Printer.trace) Printer.trace("DataPusher: source.flush()");
     source.flush();
     if (DEBUG || Printer.trace) Printer.trace("DataPusher: source.start()");
     source.start();
     if (pushThread == null) {
       if (DEBUG || Printer.debug) Printer.debug("DataPusher.start(): Starting push");
       pushThread =
           JSSecurityManager.createThread(
               this, null, // name
               false, // daemon
               -1, // priority
               true); // doStart
     }
     notifyAll();
   } catch (Exception e) {
     if (DEBUG || Printer.err) e.printStackTrace();
   }
   if (DEBUG || Printer.debug) Printer.debug("< DataPusher.start(loop=" + loop + ")");
 }
Exemplo n.º 2
0
 @Override
 public int onAudioData(byte[] data) {
   if (audioLine != null && audioLine.isOpen()) {
     if (!audioLine.isRunning()) {
       audioLine.start();
     }
     int toWrite = Math.min(audioLine.available(), data.length);
     if (toWrite == audioLine.available())
       log.trace("full! toWrite: " + toWrite + " instead of: " + data.length);
     return audioLine.write(data, 0, toWrite);
   } else {
     return 0;
   }
 }