diff --git a/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileFormat.java b/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileFormat.java index 07446e2..a10c344 100644 --- a/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileFormat.java +++ b/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileFormat.java @@ -116,6 +116,7 @@ private static float determineFrameRate(final int codecId, final float sampleRat } private static Type getAudioFileFormatType(final String url, final int codecId) throws UnsupportedAudioFileException { + if (url == null) { final AudioFormat.Encoding encoding = FFAudioFormat.FFEncoding.getInstance(codecId); final Type type = TYPE_MAP.get(codecId); @@ -149,7 +150,11 @@ private static Type getAudioFileFormatType(final String url, final int codecId) fileType = new Type(extension.toUpperCase(), extension); } } else { - throw new UnsupportedAudioFileException("Unknown target audio url type: " + url); + // For audio files without explicit extension in file name. + final AudioFormat.Encoding encoding = FFAudioFormat.FFEncoding.getInstance(codecId); + final Type type = TYPE_MAP.get(codecId); + if (type != null) return type; + return new Type(encoding.toString().toUpperCase(), encoding.toString()); } return fileType; } diff --git a/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileReader.java b/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileReader.java index 2a563f5..fd63a4a 100644 --- a/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileReader.java +++ b/ffsampledsp-java/src/main/java/com/tagtraum/ffsampledsp/FFAudioFileReader.java @@ -27,6 +27,7 @@ import javax.sound.sampled.spi.AudioFileReader; import java.io.*; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLDecoder; import java.nio.ByteBuffer; @@ -126,30 +127,31 @@ public AudioFileFormat[] getAudioFileFormats(final File file) throws Unsupported * @throws MalformedURLException if the URL is malformed */ static URL fileToURL(final File file) throws MalformedURLException { - try { - String encoded = file.toURI().toString().replace("+", "%2B"); - return new URL(URLDecoder.decode(encoded, "UTF-8")); - } catch (UnsupportedEncodingException e) { - final MalformedURLException malformedURLException = new MalformedURLException(); - malformedURLException.initCause(e); - throw malformedURLException; - } + String encoded = file.toURI().toString().replace("+", "%2B"); + return URI.create(encoded).toURL(); } /** * Make sure that file URLs on Windows follow the super special libav style, e.g. "file:C:/path/file.ext" * or "file://UNCServerName/path/file.ext". */ - static String urlToString(final URL url) { + static String urlToString(final URL url) throws UnsupportedEncodingException { if (url == null) return null; - final String s = url.toString(); - if (WINDOWS && s.matches("file\\:/[^\\/].*")) { - return s.replace("file:/", "file:"); - } - // deal with UNC paths - if (WINDOWS && s.matches("file\\:////[^\\/].*")) { - return s.replace("file://", "file:"); + + String s = url.toString(); + + // Encode "+" character + s = s.replace("+", "%2B"); + s = URLDecoder.decode(s, "UTF-8"); + + if (WINDOWS) { + if (s.matches("file\\:/[^\\/].*")) { + s = s.replace("file:/", "file:"); // (file:/) -> (file:) + } else if (s.matches("file\\:////[^\\/].*")) { + s = s.replace("file://", "file:"); // For UNC paths (file:////) -> (file://) + } } + return s; }