本文整理汇总了Java中javax.sound.sampled.AudioSystem.getAudioInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSystem.getAudioInputStream方法的具体用法?Java AudioSystem.getAudioInputStream怎么用?Java AudioSystem.getAudioInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.AudioSystem
的用法示例。
在下文中一共展示了AudioSystem.getAudioInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAIS
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Tests the {@code AudioInputStream} fetched from the fake header.
* <p>
* Note that the frameLength is stored as long which means that {@code
* AudioInputStream} must store all possible data from wave file.
*/
private static void testAIS(final int[] type, final int rate,
final int channel, final long size)
throws Exception {
final byte[] header = createHeader(type, rate, channel, size);
final ByteArrayInputStream fake = new ByteArrayInputStream(header);
final AudioInputStream ais = AudioSystem.getAudioInputStream(fake);
final AudioFormat format = ais.getFormat();
final long frameLength = size / format.getFrameSize();
if (frameLength != ais.getFrameLength()) {
System.err.println("Expected: " + frameLength);
System.err.println("Actual: " + ais.getFrameLength());
throw new RuntimeException();
}
if (ais.available() < 0) {
System.err.println("available should be >=0: " + ais.available());
throw new RuntimeException();
}
validateFormat(type[1], rate, channel, format);
}
示例2: Sound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Creates a new Sound instance by the specified file path. Loads the sound
* data into a byte array and also retrieves information about the format of
* the sound file.
*
* Note that the constructor is private. In order to load files use the static
* methods {@link #find(String)} or {@link #load(String)} methods depending on
* whether you already loaded the sound or not.
*
* @param is
* The input stream to load the sound from.
*/
private Sound(InputStream is, String name) {
this.name = name;
try {
AudioInputStream in = AudioSystem.getAudioInputStream(is);
if (in != null) {
final AudioFormat baseFormat = in.getFormat();
final AudioFormat decodedFormat = this.getOutFormat(baseFormat);
// Get AudioInputStream that will be decoded by underlying VorbisSPI
in = AudioSystem.getAudioInputStream(decodedFormat, in);
this.stream = in;
this.streamData = StreamUtilities.getBytes(this.stream);
this.format = this.stream.getFormat();
}
} catch (final UnsupportedAudioFileException | IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
示例3: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String[] params) throws Exception {
AudioInputStream is =
AudioSystem.getAudioInputStream(new
ByteArrayInputStream(new byte[] {
(byte)0x2E, (byte)0x73, (byte)0x6E, (byte)0x64, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x18,
(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x03,
(byte)0x00, (byte)0x00, (byte)0x1F, (byte)0x40, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x01,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00,
}));
if (is.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
System.out.println("frame length should be NOT_SPECIFIED, but is: "+is.getFrameLength());
failed=true;
}
//assertTrue(is.getFrameLength() == AudioSystem.NOT_SPECIFIED);
//assertTrue(is.read(new byte[8]) == 8);
//assertTrue(is.read(new byte[2]) == -1);
if (failed) throw new Exception("Test FAILED!");
System.out.println("Test Passed.");
}
示例4: getAudioInputStream
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* This method is a replacement for
* AudioSystem.getAudioInputStream(AudioFormat, AudioInputStream), which is
* used for audio format conversion at the stream level. This method includes
* a workaround for converting from an mp3 AudioInputStream when the sketch
* is running in an applet. The workaround was developed by the Tritonus team
* and originally comes from the package javazoom.jlgui.basicplayer
*
* @param targetFormat
* the AudioFormat to convert the stream to
* @param sourceStream
* the stream containing the unconverted audio
* @return an AudioInputStream in the target format
*/
AudioInputStream getAudioInputStream(AudioFormat targetFormat,
AudioInputStream sourceStream)
{
try
{
return AudioSystem.getAudioInputStream(targetFormat, sourceStream);
}
catch (IllegalArgumentException iae)
{
debug("Using AppletMpegSPIWorkaround to get codec");
try
{
Class.forName("javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider");
return new javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider().getAudioInputStream(
targetFormat,
sourceStream);
}
catch (ClassNotFoundException cnfe)
{
throw new IllegalArgumentException("Mpeg codec not properly installed");
}
}
}
示例5: initAudioInputStreamPart2
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Audio resources from File||URL||InputStream.
*
* @throws UnsupportedAudioFileException
* the unsupported audio file exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void initAudioInputStreamPart2() throws UnsupportedAudioFileException , IOException {
logger.info("Entered initAudioInputStreamPart->2\n");
if (dataSource instanceof URL) {
audioInputStream = AudioSystem.getAudioInputStream((URL) dataSource);
audioFileFormat = AudioSystem.getAudioFileFormat((URL) dataSource);
} else if (dataSource instanceof File) {
audioInputStream = AudioSystem.getAudioInputStream((File) dataSource);
audioFileFormat = AudioSystem.getAudioFileFormat((File) dataSource);
} else if (dataSource instanceof InputStream) {
audioInputStream = AudioSystem.getAudioInputStream((InputStream) dataSource);
audioFileFormat = AudioSystem.getAudioFileFormat((InputStream) dataSource);
}
logger.info("Exited initAudioInputStreamPart->2\n");
}
示例6: getAudioInputStream
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Gets an audio input stream given a file, hopefully containing audio data.
*
* @param file The {@code File} to test.
* @return An {@code AudioInputStream}, or null on failure.
* @throws Exception if the file does not contain valid audio.
*/
public static AudioInputStream getAudioInputStream(File file)
throws Exception {
AudioInputStream in;
if (file.getName().endsWith(".ogg")) {
// We used to use tritonus to provide ogg (strictly,
// Vorbis-audio-in-ogg-container) decoding to the Java
// sound system. It was buggy and appears to be
// unmaintained since 2009. So now for ogg we have our
// own jorbis-based decoder.
in = new OggVorbisDecoderFactory().getOggStream(file);
} else {
in = AudioSystem.getAudioInputStream(file);
}
return in;
}
示例7: getSoundbank
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
示例8: SoundPlayingThread
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public SoundPlayingThread(ListedSong listedSong, ProgressBar progress) {
this.listedSong = listedSong;
this.audioFile = listedSong.file;
this.progress = progress;
if (audioFile != null) {
try {
AudioInputStream audioInputStream;
if(audioFile.getName().endsWith(".ogg") || audioFile.getName().endsWith(".mp3")) {
audioInputStream = createFromOgg(audioFile);
}
else { // wav
audioInputStream = AudioSystem.getAudioInputStream(audioFile);
}
clip = AudioSystem.getClip();
clip.open(audioInputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例9: constructAIS
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void constructAIS() {
try {
ais = AudioSystem.getAudioInputStream(new File(filename));
} catch (Exception e) {
println("ERROR: could not open "+filename+": "+e.getMessage());
}
}
示例10: main
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
System.out.println();
System.out.println();
System.out.println("4399551: Repost of bug candidate: cannot replay aif file (Review ID: 108108)");
// try to read this file
AudioSystem.getAudioInputStream(new ByteArrayInputStream(SHORT_AIFC_ULAW));
System.out.println(" test passed.");
}
示例11: convertAudioInputStreamToPcmSigned
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void convertAudioInputStreamToPcmSigned() {
AudioFormat format = audioInputStream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
audioInputStream = AudioSystem.getAudioInputStream(
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
16,
1,
2,
format.getSampleRate(),
false), audioInputStream);
}
}
示例12: enableHorn
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void enableHorn () throws UnsupportedAudioFileException, IOException, LineUnavailableException
{
if ( ( this.clip == null || !this.clip.isRunning () ) && Activator.getDefault ().getPreferenceStore ().getBoolean ( PreferenceConstants.BELL_ACTIVATED_KEY ) )
{
final AudioInputStream sound = AudioSystem.getAudioInputStream ( this.soundFile );
final DataLine.Info info = new DataLine.Info ( Clip.class, sound.getFormat () );
this.clip = (Clip)AudioSystem.getLine ( info );
this.clip.open ( sound );
this.clip.loop ( Clip.LOOP_CONTINUOUSLY );
}
if ( !this.bellIcon.isDisposed () )
{
this.bellIcon.setImage ( getBellIcon () );
}
}
示例13: JavaSoundAudioClip
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public JavaSoundAudioClip(InputStream in) throws IOException {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>");
BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE);
bis.mark(STREAM_BUFFER_SIZE);
boolean success = false;
try {
AudioInputStream as = AudioSystem.getAudioInputStream(bis);
// load the stream data into memory
success = loadAudioData(as);
if (success) {
success = false;
if (loadedAudioByteLength < CLIP_THRESHOLD) {
success = createClip();
}
if (!success) {
success = createSourceDataLine();
}
}
} catch (UnsupportedAudioFileException e) {
// not an audio file
try {
MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis);
success = createSequencer(bis);
} catch (InvalidMidiDataException e1) {
success = false;
}
}
if (!success) {
throw new IOException("Unable to create AudioClip from input stream");
}
}
示例14: Sound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public Sound(String file){
try {
ais = AudioSystem.getAudioInputStream(new File(file));
clip = AudioSystem.getClip();
clip.open(ais);
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace();
}
}
示例15: calculateFingerPrint
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
@Test
public void calculateFingerPrint() throws Exception {
for(Map.Entry<URL, String> entry : tests.entrySet()) {
URL url = entry.getKey();
String hash = entry.getValue();
AudioInputStream is = AudioSystem.getAudioInputStream(url);
Chromaprint chromaprint = new Chromaprint(is);
Fingerprint fingerprint = chromaprint.calculateFingerPrint();
Assert.assertEquals(hash, fingerprint.getString());
}
}