Java Code Examples for javax.sound.sampled.SourceDataLine#Info
The following examples show how to use
javax.sound.sampled.SourceDataLine#Info .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalPlayerDemo.java From lavaplayer with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws LineUnavailableException, IOException { AudioPlayerManager manager = new DefaultAudioPlayerManager(); AudioSourceManagers.registerRemoteSources(manager); manager.getConfiguration().setOutputFormat(COMMON_PCM_S16_BE); AudioPlayer player = manager.createPlayer(); manager.loadItem("ytsearch: epic soundtracks", new FunctionalResultHandler(null, playlist -> { player.playTrack(playlist.getTracks().get(0)); }, null, null)); AudioDataFormat format = manager.getConfiguration().getOutputFormat(); AudioInputStream stream = AudioPlayerInputStream.createStream(player, format, 10000L, false); SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat()); SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(stream.getFormat()); line.start(); byte[] buffer = new byte[COMMON_PCM_S16_BE.maximumChunkSize()]; int chunkSize; while ((chunkSize = stream.read(buffer)) >= 0) { line.write(buffer, 0, chunkSize); } }
Example 2
Source File: JavaInfo.java From haxademic with MIT License | 4 votes |
public static void printAudioInfo() { P.out("----------------- printAudioInfo -------------------"); Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo(); for(int i = 0; i < mixerInfo.length; i++) { P.out("########## mixerInfo["+i+"]", mixerInfo[i].getName()); // Mixer mixer = AudioSystem.getMixer(null); // default mixer Mixer mixer = AudioSystem.getMixer(mixerInfo[i]); // default mixer try { mixer.open(); } catch (LineUnavailableException e) { e.printStackTrace(); } P.out("Supported SourceDataLines of default mixer (%s):\n\n", mixer.getMixerInfo().getName()); for(Line.Info info : mixer.getSourceLineInfo()) { if(SourceDataLine.class.isAssignableFrom(info.getLineClass())) { SourceDataLine.Info info2 = (SourceDataLine.Info) info; P.out(info2); System.out.printf(" max buffer size: \t%d\n", info2.getMaxBufferSize()); System.out.printf(" min buffer size: \t%d\n", info2.getMinBufferSize()); AudioFormat[] formats = info2.getFormats(); P.out(" Supported Audio formats: "); for(AudioFormat format : formats) { P.out(" "+format); System.out.printf(" encoding: %s\n", format.getEncoding()); System.out.printf(" channels: %d\n", format.getChannels()); System.out.printf(format.getFrameRate()==-1?"":" frame rate [1/s]: %s\n", format.getFrameRate()); System.out.printf(" frame size [bytes]: %d\n", format.getFrameSize()); System.out.printf(format.getSampleRate()==-1?"":" sample rate [1/s]: %s\n", format.getSampleRate()); System.out.printf(" sample size [bit]: %d\n", format.getSampleSizeInBits()); System.out.printf(" big endian: %b\n", format.isBigEndian()); Map<String,Object> prop = format.properties(); if(!prop.isEmpty()) { P.out(" Properties: "); for(Map.Entry<String, Object> entry : prop.entrySet()) { System.out.printf(" %s: \t%s\n", entry.getKey(), entry.getValue()); } } } P.out(); } else { P.out(info.toString()); } P.out(); } mixer.close(); } }