Программа не может их воспроизвести, жалуясь на неподходящий формат. Изменив выбор формата для вывода отладочной информации, я получил следующий Java-код:
Код: Выделить всё
protected static AudioFormat getFormatForPlaying(byte [] audioData)
throws UnsupportedAudioFileException, IOException{
ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
AudioFormat format = AudioSystem.getAudioFileFormat(bais).getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
if (AudioSystem.isLineSupported(info)) {
System.err.println("Audio format ``" + format + "'' can be used straight");
return format;
}
System.err.println("Audio format ``" + format + "'' can not be used straight");
AudioFormat[] possibleFormats = AudioSystem.getTargetFormats(
AudioFormat.Encoding.PCM_SIGNED, format);
for (AudioFormat newFormat : possibleFormats) {
info = new DataLine.Info(SourceDataLine.class, newFormat);
if (AudioSystem.isLineSupported(info)) {
System.err.println("Will try audio format " + newFormat + " instead of " + format);
return newFormat;
}
System.err.println("Format ``" + newFormat + "'' cannot be used");
}
throw new UnsupportedAudioFileException("No suitable audio format among " +
possibleFormats.length + " possibilities");
}
Код: Выделить всё
Audio format ``ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, '' can not be used straight
Format ``PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian'' cannot be used
Format ``PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian'' cannot be used
javax.sound.sampled.UnsupportedAudioFileException: No suitable audio format among 2 possibilities
Это действительно правда? Если да, то есть ли простой выход, например, использование какого-нибудь известного и распространенного пакета преобразования?
(Например, когда я воспроизвожу те же звуковые файлы с помощью mplayer, он сообщает, что автоматически преобразует их из 8 кГц в 16 кГц.)
Подробнее здесь: https://stackoverflow.com/questions/798 ... java-today
Мобильная версия