写一个长按3倍速播放的java代码
时间: 2023-03-15 13:36:11 浏览: 73
public void playAt3XSpeed(String musicFile){
File file = new File(musicFile);
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate() * 3,
false);
AudioInputStream din = AudioSystem.getAudioInputStream(decodedFormat, in);
try {
SourceDataLine line = AudioSystem.getSourceDataLine(decodedFormat);
line.open(decodedFormat);
line.start();
int nByte = 0;
byte[] buffer = new byte[4096];
while(nByte != -1){
nByte = din.read(buffer, 0, buffer.length);
if(nByte >= 0){
line.write(buffer, 0, nByte);
}
}
line.drain();
line.close();
} catch (LineUnavailableException | IOException e) {
e.printStackTrace();
}
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)