我正在使用amazon s3 bucket技术,我有一个从.wav
文件的部分下载字节的程序,例如,我会调用类似
getPartOfASongFile(String filename, long byteToStartAt, long byteToEndAt)` and then play it using a Clip.
该程序的工作时间与byteToStartAt==0
一样长。任何高于0的东西我都会得到一个
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file`.
我的问题是:如果我想让byteToStartAt大于零,我该如何播放这个文件?
这基本上是当前的程序:
getPartOfASongFile(String filename,long byteToStartAt,long byteToEndAt){
File tempFile= null;
try {
tempFile = File.createTempFile(filename, ".wav");
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
tempFile.deleteOnExit();
FileOutputStream out=null;
try {
out = new FileOutputStream(tempFile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
GetObjectRequest rangeObjectRequest=new GetObjectRequest("myBucketName",filename);
rangeObjectRequest.setRange(byteToStartAt, byteToEndAt);
try {
IOUtils.copy(awsClient.getObject(rangeObjectRequest).getObjectContent(), out);
} catch (AmazonClientException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AudioInputStream audioInputStream=null;
audioInputStream = AudioSystem.getAudioInputStream(tempFile);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
}