これは改善だと思います。n個のオーディオファイルに適しています。
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.IAudioSamples;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IPacket;
import com.xuggle.xuggler.IStreamCoder;
public class Concatenador_Audios {
public static void main(String[] args) {
ConcatenarAudios("D:\\out concatenate.mp3", "D:\\in Audio (1).mp3", "D:\\in Audio (2).mp3", "D:\\in Audio (3).mp3");
}
public static void ConcatenarAudios(String Ruta_AudioConcatenado,String... ruta_Audio) {
int n = ruta_Audio.length;
IMediaWriter mWriter = ToolFactory.makeWriter(Ruta_AudioConcatenado);
IPacket packet = IPacket.make();
for (int i = 0; i < n; i++) {
IContainer container = IContainer.make();
container.open(ruta_Audio[i], IContainer.Type.READ, null);
IStreamCoder audio = container.getStream(0).getStreamCoder();
audio.open(null, null);
if (i == 0) {
mWriter.addAudioStream(0, 0, audio.getChannels(), audio.getSampleRate());
}
while (container.readNextPacket(packet) >= 0) {
IAudioSamples samples = IAudioSamples.make(512, audio.getChannels(), IAudioSamples.Format.FMT_S32);
audio.decodeAudio(samples, packet, 0);
mWriter.encodeAudio(0, samples);
}
container.close();
audio.close();
}
mWriter.close();
}
}
}