Examples of AudioInputStream


Examples of javax.sound.sampled.AudioInputStream

            break;

        case WAV:
            try
            {
                AudioInputStream stream = AudioSystem.getAudioInputStream(new BufferedInputStream(resource.getInputStream()));
                decoder                 = new PCMStreamConverter(stream, stream.getFormat(), outputNumSamplesPerChannel);

                mNumChannels = stream.getFormat().getChannels();
                mSampleRate  = (int)stream.getFormat().getSampleRate();
            }
            catch(Exception exception) { decoder = null; }
            break;
        }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

   */
  public void playErrorSound() {
    if (Configuration.getInstance().isPlaySounds()) {
      try {
        if (errorClip == null) {
          AudioInputStream sound = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream(
              ERROR_SOUND));
          DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
          errorClip = (Clip) AudioSystem.getLine(info);
          errorClip.open(sound);
        }
        executor.execute(new PlayThread(errorClip));
      } catch (Exception e) {
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

   */
  public void playSound() {
    if (Configuration.getInstance().isPlaySounds()) {
      try {
        if (soundClip == null) {
          AudioInputStream sound = AudioSystem
              .getAudioInputStream(this.getClass().getResourceAsStream(SOUND));
          DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
          soundClip = (Clip) AudioSystem.getLine(info);
          soundClip.open(sound);
        }
        executor.execute(new PlayThread(soundClip));
      } catch (Exception e) {
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

      file = File.createTempFile((new File(filename)).getName(), ".wav");
      file.deleteOnExit();
      decodedFiles.put(key, file);

      File encodedFile = new File(filename);
      AudioInputStream decodedInputStream = AudioSystem
          .getAudioInputStream(encodedFile);
      // Convert to PCM
      decodedInputStream = AudioSystem.getAudioInputStream(
                AudioFormat.Encoding.PCM_SIGNED, decodedInputStream);
      AudioSystem.write(decodedInputStream, AudioFileFormat.Type.WAVE,
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

    // Write to the output stream
    pos = new PipedOutputStream();

    // It will then go to the file via the input streams
    pis = new PipedInputStream(pos);
    ais = new AudioInputStream(pis, format, AudioSystem.NOT_SPECIFIED);
   
    new Thread(this).start();
  }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

      // Write to the output stream
      pos = new PipedOutputStream();

      // It will then go to the file via the input streams
      pis = new PipedInputStream(pos);
      ais = new AudioInputStream(pis, format, AudioSystem.NOT_SPECIFIED);

      new Thread(this).start();
    }
  }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

    // Write to the output stream
    pos = new PipedOutputStream();

    // It will then go to the file via the input streams
    pis = new PipedInputStream(pos);
    ais = new AudioInputStream(pis, format, AudioSystem.NOT_SPECIFIED);

    new Thread(this).start();
  }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

   
    /**
     * Play the audio resource
     */
    public void play() {
        AudioInputStream audioInputStream = null;
        try {
            audioInputStream = AudioSystem.getAudioInputStream(resourceURL);
            AudioFormat audioFormat = audioInputStream.getFormat();
            DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioFormat);
            Clip clip = getClip(dataLineInfo);
            clip.open(audioInputStream);
            FloatControl volctrl=(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
            volctrl.setValue(volume);
            clip.start();
        } catch (UnsupportedAudioFileException ex) {
            resourceLogger.log(Level.SEVERE, null, ex);
        } catch (LineUnavailableException ex) {
            resourceLogger.warning("cannot play audio resource, due to " + ex.getLocalizedMessage());
        } catch (IOException ex) {
            resourceLogger.log(Level.SEVERE, null, ex);
        } finally {
            try {
                audioInputStream.close();
            } catch (IOException ex) {
                resourceLogger.log(Level.SEVERE, null, ex);
            }
        }
    }
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

     */

    @Override
    public void run() {

        AudioInputStream audioInputStream = null;
        try {
            audioInputStream = AudioSystem.getAudioInputStream(this.inputStream);
        } catch (final UnsupportedAudioFileException e1) {
            e1.printStackTrace();
            return;
        } catch (final IOException e1) {
            e1.printStackTrace();
            return;
        }

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

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

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

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

        try {
            while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0) {
                    auline.write(abData, 0, nBytesRead);
                }
            }
        } catch (final IOException e) {
View Full Code Here

Examples of javax.sound.sampled.AudioInputStream

    auline.close();
  }

  public void run()
  {
    AudioInputStream audioInputStream = null;
    try
    {
      audioInputStream = AudioSystem.getAudioInputStream(url);
    }
    catch (UnsupportedAudioFileException e1)
    {
      e1.printStackTrace();
      return;
    }
    catch (IOException e1)
    {
      e1.printStackTrace();
      return;
    }

    AudioFormat format = audioInputStream.getFormat();
   
    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)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.