import javax.media.format.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.*;
public class test {
public static void main(String[] args) {
AudioInputStream ais;
ais= AudioSystem.getAudioInputStream(new File("C:\\d\\流着泪说分手.mp3"));
javax.sound.sampled.AudioFormat baseFormat = ais.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,baseFormat.getSampleRate(),16,baseFormat.getChannels(),baseFormat.getChannels() * 2,baseFormat.getSampleRate(),false);
ais = AudioSystem.getAudioInputStream(decodedFormat, ais);
}
}
这是我刚刚写的一点小代码,我是想将ais中的格式转换一下,可是AudioFormat.Encoding.PCM_SIGNED一直报错,错误为:Encoding cannot be resolved or is not a field。
而且ais = AudioSystem.getAudioInputStream(decodedFormat, ais);中,decodedFormat一直说是格式不对
然后eclipse让我把decodedFormat类型改成Encoding,求教这是为什么呀?
我定义的decodedFormat的类型就是AudioFormat啊,为啥说格式不对呢?求指导,不胜感激……