Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.io.*;
import javax.sound.sampled.*;
public class TestSound
{
public static void main(String[] args) throws Exception { new TestSound(args); }
private TestSound(String[] args) throws Exception
{
File soundFile=new File(args[0]);
AudioInputStream audioInputStream=AudioSystem.getAudioInputStream(soundFile);
Clip clip=AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
while(clip.getFramePosition()<clip.getFrameLength()) { }
}
}
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.*;
public class MP3
{
public static Clip loadClip(File file)
{
try {
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false
);
AudioInputStream inputStream = AudioSystem.getAudioInputStream(decodedFormat, in);
DataLine.Info info = new DataLine.Info(Clip.class, inputStream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(in);
clip.addLineListener(new ClipLineListener());
return clip;
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
return null;
}
private static class ClipLineListener implements LineListener
{
/* (non-Javadoc)
* @see javax.sound.sampled.LineListener#update(javax.sound.sampled.LineEvent)
*/
public void update(LineEvent event)
{
if(LineEvent.Type.STOP == event.getType()) {
event.getLine().close();
}
}
}
}
SCHWERWIEGEND: null
javax.sound.sampled.LineUnavailableException: Failed to allocate clip data: Requested buffer too large.
at com.sun.media.sound.MixerClip.implOpen(MixerClip.java:561)
at com.sun.media.sound.MixerClip.open(MixerClip.java:165)
at com.sun.media.sound.MixerClip.open(MixerClip.java:256)
at jonny_0_5.MusicBox.<init>(MusicBox.java:52)
at jonny_0_5.Board.preloader(Board.java:96)
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1102)