Package javax.sound.sampled

Examples of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream


        }
 
        private void playSingleLine(byte[] data, AudioFormat format)
        {
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            AudioInputStream stream = new AudioInputStreambais, format,data.length / format.getFrameSize());

            Line.Info linfo = new Line.Info (Clip.class);
            Clip clip=null;
            try
            {
View Full Code Here


        for (int i = 0; i < audioStrings.length; i++) {
          if (actionKey.equals(audioStrings[i])){
            try {
              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) {
View Full Code Here

    if (data.length>1)
    try
    {
      ByteArrayInputStream dis2=new ByteArrayInputStream(data);

      AudioInputStream stream = AudioSystem.getAudioInputStream(dis2);

      // From URL
      // stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));

      // At present, ALAW and ULAW encodings must be converted
      // to PCM_SIGNED before it can be played
      AudioFormat format = stream.getFormat();
      if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED)
      {
          format = new AudioFormat(
                  AudioFormat.Encoding.PCM_SIGNED,
                  format.getSampleRate(),
                  format.getSampleSizeInBits()*2,
                  format.getChannels(),
                  format.getFrameSize()*2,
                  format.getFrameRate(),
                  true);        // big endian
          stream = AudioSystem.getAudioInputStream(format, stream);
      }
      DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
      clip = (Clip) AudioSystem.getLine(info);
      clip.open(stream);
      //clip.start();

     
View Full Code Here

                line.open(audioFormat);
            } catch (LineUnavailableException e) {
                log.error("TargetDataLine is already in use.");
                return false;
            }
            audioInputStream = new AudioInputStream(line);
            audioInputStream = AudioSystem.getAudioInputStream(audioFormat,
                audioInputStream);

            line.start();
            started = true;
View Full Code Here

                    if ((soundFile == null) || !soundFile.exists()) {
                        log.warn("Wave file not found at " + fileName);
                        return;
                    }

                    AudioInputStream audioInputStream = null;
                    try {
                        audioInputStream = AudioSystem
                            .getAudioInputStream(soundFile);
                    } catch (UnsupportedAudioFileException e1) {
                        log.warn("Unsupported File: " + fileName, e1);
                        return;
                    } catch (IOException e1) {
                        log.error(
                            "IO-Error while getting AudioInputStream for "
                                + 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) {
View Full Code Here

        }

        ByteArrayInputStream byteInputArrayStream = new ByteArrayInputStream(
                audioBytes);

        AudioInputStream audioInputStream = new AudioInputStream(
                byteInputArrayStream, _playToFileFormat, audioBytes.length
                        / _frameSizeInBytes);

        outFile = new File(_fileName);
View Full Code Here

            Byte j = (Byte) _toFileBuffer.get(i);
            audioBytes[i] = j.byteValue();
        }

        ByteArrayInputStream byteInputArrayStream = null;
        AudioInputStream audioInputStream = null;

        try {
            byteInputArrayStream = new ByteArrayInputStream(audioBytes);

            audioInputStream = new AudioInputStream(byteInputArrayStream,
                    _playToFileFormat, audioBytes.length / _frameSizeInBytes);

            File outFile = new File(_fileName);

            StringTokenizer st = new StringTokenizer(_fileName, ".");

            // Do error checking:
            if (st.countTokens() != 2) {
                throw new IOException("Error: Incorrect "
                        + "file name format. " + "Format: filename.extension");
            }

            st.nextToken(); // Advance to the file extension.

            String fileExtension = st.nextToken();

            if (fileExtension.equalsIgnoreCase("au")) {
                // Save the file.
                AudioSystem.write(audioInputStream, AudioFileFormat.Type.AU,
                        outFile);
            } else if (fileExtension.equalsIgnoreCase("aiff")) {
                // Save the file.
                AudioSystem.write(audioInputStream, AudioFileFormat.Type.AIFF,
                        outFile);
            } else if (fileExtension.equalsIgnoreCase("wave")) {
                // Save the file.
                AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE,
                        outFile);
            } else if (fileExtension.equalsIgnoreCase("wav")) {
                // Save the file.
                AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE,
                        outFile);
            } else if (fileExtension.equalsIgnoreCase("aifc")) {
                // Save the file.
                AudioSystem.write(audioInputStream, AudioFileFormat.Type.AIFC,
                        outFile);
            } else {
                throw new IOException("Error saving "
                        + "file: Unknown file format: " + fileExtension);
            }
        } catch (IOException e) {
            throw new IOException("SoundPlayback: error saving" + " file: " + e);
        } finally {
            if (byteInputArrayStream != null) {
                try {
                    byteInputArrayStream.close();
                } catch (Throwable throwable) {
                    System.out.println("Ignoring failure to close stream "
                            + "on " + audioBytes.length + " bytes of data.");
                    throwable.printStackTrace();
                }
            }

            if (audioInputStream != null) {
                try {
                    audioInputStream.close();
                } catch (Throwable throwable) {
                    System.out.println("Ignoring failure to close stream "
                            + "on " + audioBytes.length + " bytes of data.");
                    throwable.printStackTrace();
                }
View Full Code Here

                    }
                }
                try {
                    Clip clip = AudioSystem.getClip();
                    clip.addLineListener(this);
                    AudioInputStream stream = null;
                    try {
                        stream = AudioSystem
                            .getAudioInputStream(fileOrURL.asURL());
                    } catch (IOException ex) {
                        // Handle jar urls from WebStart or the installer
View Full Code Here

   * @throws LineUnavailableException
   *
   */
  public void play(String fileName) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
    URL url = new UrlUtil().getUrl(fileName);
    AudioInputStream stream = AudioSystem.getAudioInputStream(url);     
    AudioFormat format = stream.getFormat();
    DataLine.Info info = new DataLine.Info(Clip.class, format);     
    Clip clip = (Clip) AudioSystem.getLine(info);        
    clip.open(stream);     
    clip.start();
  }
View Full Code Here

        url = PSAUtil.class.getResource("/sounds/beep-6.wav").toURI().toURL();
      } catch (URISyntaxException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      AudioInputStream audioInputStream = AudioSystem
          .getAudioInputStream(url);
      Clip clip = AudioSystem.getClip();
      clip.open(audioInputStream);
      clip.start();
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream

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.