/** * List the available audio file format types, as a multi-line string. Each line consists of the name of an Audio file format * type, followed by a suffix "_FILE" if the format can be produced as a file, and "_STREAM" if the format can be streamed. * * @return a multi-line string, or an empty string if no audio file types are available. */ public static String getAudioFileFormatTypes() { StringBuilder output = new StringBuilder(); AudioFileFormat.Type[] audioTypes = AudioSystem.getAudioFileTypes(); for (int t = 0; t < audioTypes.length; t++) { AudioFileFormat.Type audioType = audioTypes[t]; String typeName = audioType.toString(); boolean isSupported = true; if (typeName.equals("MP3")) isSupported = canCreateMP3(); else if (typeName.equals("Vorbis")) isSupported = canCreateOgg(); audioType = MaryAudioUtils.getAudioFileFormatType(typeName); if (audioType == null) { isSupported = false; } if (isSupported && AudioSystem.isFileTypeSupported(audioType)) { output.append(typeName).append("_FILE\n"); if (typeName.equals("MP3") || typeName.equals("Vorbis")) output.append(typeName).append("_STREAM\n"); } } return output.toString(); }
/** * List the available audio file format types, as a multi-line string. Each line consists of the name of an Audio file format * type, followed by a suffix "_FILE" if the format can be produced as a file, and "_STREAM" if the format can be streamed. * * @return a multi-line string, or an empty string if no audio file types are available. */ public static String getAudioFileFormatTypes() { StringBuilder output = new StringBuilder(); AudioFileFormat.Type[] audioTypes = AudioSystem.getAudioFileTypes(); for (int t = 0; t < audioTypes.length; t++) { AudioFileFormat.Type audioType = audioTypes[t]; String typeName = audioType.toString(); boolean isSupported = true; if (typeName.equals("MP3")) isSupported = canCreateMP3(); else if (typeName.equals("Vorbis")) isSupported = canCreateOgg(); audioType = MaryAudioUtils.getAudioFileFormatType(typeName); if (audioType == null) { isSupported = false; } if (isSupported && AudioSystem.isFileTypeSupported(audioType)) { output.append(typeName).append("_FILE\n"); if (typeName.equals("MP3") || typeName.equals("Vorbis")) output.append(typeName).append("_STREAM\n"); } } return output.toString(); }
if (!MaryRuntimeUtils.canCreateMP3()) { throw new UnsupportedAudioFileException("Conversion to MP3 not supported.");
if (!MaryRuntimeUtils.canCreateMP3()) { throw new UnsupportedAudioFileException("Conversion to MP3 not supported.");
MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), null); return; } else if (audioFileFormatType.toString().equals("MP3") && !MaryRuntimeUtils.canCreateMP3()) { MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), "Conversion to MP3 not supported.");
MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), null); return; } else if (audioFileFormatType.toString().equals("MP3") && !MaryRuntimeUtils.canCreateMP3()) { MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), "Conversion to MP3 not supported.");
@Test public void testMP3Available() throws Exception { AudioFormat mp3af = new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); AudioInputStream waveStream = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream("test.wav")); // Now attempt conversion: if (MaryRuntimeUtils.canCreateMP3()) { assertTrue(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3af, waveStream); } else { assertFalse(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); } } }
@Test public void testMP3Available() throws Exception { AudioFormat mp3af = new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); AudioInputStream waveStream = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream("test.wav")); // Now attempt conversion: if (MaryRuntimeUtils.canCreateMP3()) { assertTrue(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3af, waveStream); } else { assertFalse(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); } } }
/** * List the available audio file format types, as a multi-line string. Each line consists of the name of an Audio file format * type, followed by a suffix "_FILE" if the format can be produced as a file, and "_STREAM" if the format can be streamed. * * @return a multi-line string, or an empty string if no audio file types are available. */ public static String getAudioFileFormatTypes() { StringBuilder output = new StringBuilder(); AudioFileFormat.Type[] audioTypes = AudioSystem.getAudioFileTypes(); for (int t = 0; t < audioTypes.length; t++) { AudioFileFormat.Type audioType = audioTypes[t]; String typeName = audioType.toString(); boolean isSupported = true; if (typeName.equals("MP3")) isSupported = canCreateMP3(); else if (typeName.equals("Vorbis")) isSupported = canCreateOgg(); audioType = MaryAudioUtils.getAudioFileFormatType(typeName); if (audioType == null) { isSupported = false; } if (isSupported && AudioSystem.isFileTypeSupported(audioType)) { output.append(typeName).append("_FILE\n"); if (typeName.equals("MP3") || typeName.equals("Vorbis")) output.append(typeName).append("_STREAM\n"); } } return output.toString(); }
if (!MaryRuntimeUtils.canCreateMP3()) { throw new UnsupportedAudioFileException("Conversion to MP3 not supported.");
MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), null); return; } else if (audioFileFormatType.toString().equals("MP3") && !MaryRuntimeUtils.canCreateMP3()) { MaryHttpServerUtils.errorWrongQueryParameterValue(response, "AUDIO", queryItems.get("AUDIO"), "Conversion to MP3 not supported.");