Package javax.sound.sampled

Examples of javax.sound.sampled.SourceDataLine


      super("Play Sound");
    }
  protected void executeActivity(ProcessInstance instance) throws Exception {
    AudioInputStream audioInputStream = null;
    SourceDataLine auline = null;

    try {
      try {
        File soundFile = this.getSoundFile().getFile();
        audioInputStream = AudioSystem.getAudioInputStream(soundFile);
      } catch (Exception e) {
        URL url = new URL(evaluateContent(instance, this.getSoundUrl()).toString());
        audioInputStream = AudioSystem.getAudioInputStream(url);
      }

      AudioFormat format = audioInputStream.getFormat();
      DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);

      if (auline.isControlSupported(FloatControl.Type.PAN)) {
        FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);

        if (curPosition == Position.RIGHT) {
          pan.setValue(1.0f);
        } else if (curPosition == Position.LEFT) {
          pan.setValue(-1.0f);
        }
      }

      auline.start();

      int nBytesRead = 0;
      byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

      while (nBytesRead != -1) {
        nBytesRead = audioInputStream.read(abData, 0, abData.length);
        if (nBytesRead >= 0) {
          auline.write(abData, 0, nBytesRead);
        }
      }
     
      auline.drain();
     
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (auline != null) try { auline.close(); } catch (Exception e1) { }
      if (audioInputStream != null) try { audioInputStream.close(); } catch (Exception e1) { }
    }
    fireComplete(instance);
View Full Code Here


      e1.printStackTrace();
      return;
    }
    AudioFormat format = audioInputStream.getFormat();
    SourceDataLine auline = null;
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
    try {
      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);
    } catch (LineUnavailableException e) {
      e.printStackTrace();
      return;
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
    if (auline.isControlSupported(FloatControl.Type.PAN)) {
      FloatControl pan = (FloatControl) auline
          .getControl(FloatControl.Type.PAN);
      if (curPosition == Position.RIGHT)
        pan.setValue(1.0f);
      else if (curPosition == Position.LEFT)
        pan.setValue(-1.0f);
    }
    auline.start();
    int nBytesRead = 0;
    byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
    try {
      while (nBytesRead != -1) {
        nBytesRead = audioInputStream.read(abData, 0, abData.length);
        if (nBytesRead >= 0)
          auline.write(abData, 0, nBytesRead);
      }
    } catch (IOException e) {
      e.printStackTrace();
      return;
    } finally {
      auline.drain();
      auline.close();
    }
  }
View Full Code Here

            e1.printStackTrace();
            return;
        }

        AudioFormat format = audioInputStream.getFormat();
        SourceDataLine auline = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

        try {
            auline = (SourceDataLine) AudioSystem.getLine(info);
            auline.open(format);
        } catch (LineUnavailableException e) {
            e.printStackTrace();
            return;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        if (auline.isControlSupported(FloatControl.Type.PAN)) {
            FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);
            if (curPosition == Position.RIGHT) {
                pan.setValue(1.0f);
            } else if (curPosition == Position.LEFT) {
                pan.setValue(-1.0f);
            }
        }

        auline.start();
        int nBytesRead = 0;
        byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

        try {
            while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0) {
                    auline.write(abData, 0, nBytesRead);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            auline.drain();
            auline.close();
        }

    }
View Full Code Here

              String audioFileName = (String)UIManager.get(audioStrings[i]);
              URL audioURL = Win32LookAndFeel.class.getResource(audioFileName);
              AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(audioURL.getFile()));
              AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              SourceDataLine auline = (SourceDataLine) AudioSystem.getLine(info);
              auline.open(format);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[524288];

              while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                  auline.write(abData, 0, nBytesRead);
              }

            } catch (UnsupportedAudioFileException e) {
              // do noting
            } catch (IOException e) {
View Full Code Here

              String audioFileName = (String)UIManager.get(audioStrings[i]);
              URL audioURL = Win32LookAndFeel.class.getResource(audioFileName);
              AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(audioURL.getFile()));
              AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              SourceDataLine auline = (SourceDataLine) AudioSystem.getLine(info);
              auline.open(format);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[524288];

              while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                  auline.write(abData, 0, nBytesRead);
              }

            } catch (UnsupportedAudioFileException e) {
              // do noting
            } catch (IOException e) {
View Full Code Here

    }
    thread = null;
  }

  private SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException {
    SourceDataLine res = null;
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
    res = (SourceDataLine) AudioSystem.getLine(info);
    res.open(audioFormat);
    return res;
  }
View Full Code Here

    }
    thread = null;
  }

  private SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException {
    SourceDataLine res = null;
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
    res = (SourceDataLine) AudioSystem.getLine(info);
    res.open(audioFormat);
    return res;
  }
View Full Code Here

              String audioFileName = (String)UIManager.get(audioStrings[i]);
              URL audioURL = Win32LookAndFeel.class.getResource(audioFileName);
              AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(audioURL.getFile()));
              AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              SourceDataLine auline = (SourceDataLine) AudioSystem.getLine(info);
              auline.open(format);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[524288];

              while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                  auline.write(abData, 0, nBytesRead);
              }

            } catch (UnsupportedAudioFileException e) {
              // do noting
            } catch (IOException e) {
View Full Code Here

                                + fileName, e1);
                        return;
                    }

                    AudioFormat format = audioInputStream.getFormat();
                    SourceDataLine auline = null;
                    DataLine.Info info = new DataLine.Info(
                        SourceDataLine.class, format);

                    try {
                        auline = (SourceDataLine) AudioSystem.getLine(info);
                        auline.open(format);
                    } catch (LineUnavailableException e) {
                        log.error("No Audioline available for " + fileName, e);
                        return;
                    } catch (Exception e) {
                        log.error("unknowen error while playing sound:"
                            + fileName, e);
                        return;
                    }

                    auline.start();
                    int nBytesRead = 0;
                    byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];

                    try {
                        while (nBytesRead != -1) {
                            nBytesRead = audioInputStream.read(abData, 0,
                                abData.length);
                            if (nBytesRead >= 0)
                                auline.write(abData, 0, nBytesRead);
                        }
                    } catch (IOException e) {
                        log.error(
                            "IO-Error while write auline for " + fileName, e);
                        return;
                    } finally {
                        auline.drain();
                        auline.close();
                    }

                }
            });
        }
View Full Code Here

                System.out.println("                       "+supFormats[j]);
        }
        //  AudioFormat[] DataLine.Info.getFormats()

        try {
            SourceDataLine line = (SourceDataLine)mixer.getLine(lInfo[0]);

            // get Controls
            Control controls[] = line.getControls();
            System.out.println("    available Controls on Line 0:");
            for (int i = 0; i < controls.length; i++)
                System.out.println("        Control["+i+"]: "+controls[i]);

            System.out.println("");
View Full Code Here

TOP

Related Classes of javax.sound.sampled.SourceDataLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.