parent
5334cb5391
commit
4122bfa034
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
|
||||
public class Audio {
|
||||
|
||||
byte[] b = new byte[1024 * 1024 * 15];
|
||||
|
||||
public void loop() {
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
int len = 0;
|
||||
sourceDataLine.open(audioFormat, 1024 * 1024 * 15);
|
||||
sourceDataLine.start();
|
||||
//System.out.println(audioInputStream.markSupported());
|
||||
audioInputStream.mark(12358946);
|
||||
while ((len = audioInputStream.read(b)) > 0) {
|
||||
sourceDataLine.write(b, 0, len);
|
||||
}
|
||||
audioInputStream.reset();
|
||||
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private AudioFormat audioFormat = null;
|
||||
private SourceDataLine sourceDataLine = null;
|
||||
private DataLine.Info dataLine_info = null;
|
||||
|
||||
private AudioInputStream audioInputStream = null;
|
||||
|
||||
public Audio(String fileName) {
|
||||
try {
|
||||
audioInputStream = AudioSystem.getAudioInputStream(Audio.class.getClassLoader().getResource(fileName));
|
||||
audioFormat = audioInputStream.getFormat();
|
||||
dataLine_info = new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLine_info);
|
||||
//FloatControl volctrl=(FloatControl)sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
//volctrl.setValue(-40);//
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
try {
|
||||
byte[] b = new byte[1024 * 5];
|
||||
int len = 0;
|
||||
sourceDataLine.open(audioFormat, 1024 * 5);
|
||||
sourceDataLine.start();
|
||||
System.out.println(audioInputStream.markSupported());
|
||||
// audioInputStream.mark(12358946);
|
||||
while ((len = audioInputStream.read(b)) > 0) {
|
||||
sourceDataLine.write(b, 0, len);
|
||||
}
|
||||
// audioInputStream.reset();
|
||||
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
audioInputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Audio a = new Audio("audio/explode.wav");
|
||||
Audio a = new Audio("audio/war1.wav");
|
||||
a.loop();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.example.tankbattle;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ImageUtil {
|
||||
public static BufferedImage rotateImage(final BufferedImage bufferedimage,
|
||||
final int degree) {
|
||||
int w = bufferedimage.getWidth();
|
||||
int h = bufferedimage.getHeight();
|
||||
int type = bufferedimage.getColorModel().getTransparency();
|
||||
BufferedImage img;
|
||||
Graphics2D graphics2d;
|
||||
(graphics2d = (img = new BufferedImage(w, h, type))
|
||||
.createGraphics()).setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);
|
||||
graphics2d.drawImage(bufferedimage, 0, 0, null);
|
||||
graphics2d.dispose();
|
||||
return img;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 847 B |
After Width: | Height: | Size: 271 KiB |
Loading…
Reference in new issue