java - 反向播放,java

标签 java audio javasound javax.sound.sampled

<分区>

我确实需要你的帮助。 如何调整以下代码以向后播放 .wav 文件?

任何帮助将不胜感激..谢谢。 卡洛斯

import java.io.*;
import javax.sound.sampled.*;

public class WavPlay {
   public static void main(String[] args) {
      SourceDataLine soundLine = null;
      int BUFFER_SIZE = 64*1024;  // 64 KB

      // Set up an audio input stream piped from the sound file.
      try {
         File soundFile = new File("chord.wav");
         AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
         AudioFormat audioFormat = audioInputStream.getFormat();
         DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
         soundLine = (SourceDataLine) AudioSystem.getLine(info);
         soundLine.open(audioFormat);
         soundLine.start();
         System.out.println("File chord.wav....playing");
         int nBytesRead = 0;
         byte[] sampledData = new byte[BUFFER_SIZE];

         while (nBytesRead != -1) {
            nBytesRead = audioInputStream.read(sampledData, 0, sampledData.length);
            if (nBytesRead >= 0) {
               // Writes audio data to the mixer via this source data line.
               soundLine.write(sampledData, 0, nBytesRead);

            }

         }
      } catch (UnsupportedAudioFileException ex) {
         ex.printStackTrace();
      } catch (IOException ex) {
         ex.printStackTrace();
      } catch (LineUnavailableException ex) {
         ex.printStackTrace();
      } finally {
         soundLine.drain();
         soundLine.close();
      }
   }

}

最佳答案

是的!有可能,很久以前我已经为此悬赏了。 Here is the link to my question .问题是我必须以自己的方式找到它。

关于java - 反向播放,java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4118640/

相关文章:

iphone - 在iPhone上播放内置声音

java - 如何编写可分析的线程转储格式

java - Android WebView : only loads HTML, 不加载 JS 或 CSS(在某些设备中)

c# - 保存每秒更改一次的数组中的数据

java - 为什么我会得到 java.lang.IllegalArgumentException : No line matching interface SourceDataLine supporting format MPEG1L3 44100. 0 ....

java - 在将声音写入文件之前,如何在不使用 java 中的 'clip' 的情况下循环播放声音

java - 我如何在这个程序中调用这个Applet?

java - 我如何更改其中一门类(class),以便允许学生以多个分数参加多项测试?

java - 轻量级运行时 "build system"

android - 在APK文件中插入音频