0
여기에 내 문제입니다, 누군가가 내게 잘 이해한다면, arraylist에 몇 가지 사운드 샘플을 넣어, 내게 기능을 주었다.오디오와 arraylist을 .wav 파일 (자바)
이 오디오 트랙이있는 .wav 파일을 만들고 싶습니다. 정말 어떻게 해야할지 잘 모릅니다. 여기
어쩌면 난 그냥 그것을 전혀 이해하지 않기 때문에 여기 ...,public class Track {
private ArrayList<Sample> sounds;
private AudioFormat audioFormat;
TargetDataLine targetDataLine;
public Track()
{
this.sounds = new ArrayList <Sample>();
}
/*** Sort the sample on the track by ascending start time ***/
public void sortTrack() {
Collections.sort(sounds);
}
/**
* Add a sample to the track.
* @param fic location to the audio file.
* @param sT set the start time in ms of the sound on the track.
*/
public void addSound(String fic, long sT) {
sounds.add(new Sample(fic, sT));
}
/**
* Delete a sample to the track.
* @param fic location to the audio file.
* @param sT set the start time in ms of the sound on the track.
*/
public void deleteSound(String fic, long sT) {
int i;
for (i = 0; i < sounds.size() &&(
sounds.get(i).getAudioFile().getName() == fic &&
sounds.get(i).getStartTime() == sT); ++i) {}
if (i < sounds.size()) sounds.remove(i);
}
코드입니다 위의 코드에서 가져온 샘플입니다.
public Sample (String fileLocation, long sT) {
try{
audioFile = new File(fileLocation);
istream = AudioSystem.getAudioInputStream(audioFile);
format = istream.getFormat();
startTime = sT;
timeLenght = (audioFile.length()/(format.getFrameSize() * format.getFrameRate())) * 1000;
}
catch (UnsupportedAudioFileException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
"샘플"은 어떻게 정의 되었습니까? 수입을 포함하십시오. 또한 #deleteSound (String, long) . 하나 들어, 문자열 비교는 == 참조 동일성 비교자를 결코 사용하지 않아야하지만, 항상 #equals (Object) 메소드를 사용해야합니다 .Java Strings는 원시적 인 값이 아니기 때문에 객체입니다. 수집은 나쁜 습관입니다. iterator와 #remove() 연산. – hiergiltdiestfu