📄 sound.java
字号:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;
/*
* Created on 2005-4-12
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author wwg
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class Sound {
String fileName = "/wav/ground.mid";
String soundType = "audio/midi";
Player play = null;
public void getPlayer() {
try {
if (play == null || play.getState() == Player.CLOSED) {
play = Manager.createPlayer(getClass().getResourceAsStream(this.fileName),
this.soundType);
play.prefetch();
play.realize();
}
} catch (IOException e) {
e.printStackTrace();
} catch (javax.microedition.media.MediaException e) {
e.printStackTrace();
}
}
public void getPlayer(byte[] data, String soundType) {
try {
if (play == null || play.getState() == Player.CLOSED) {
if (soundType != null && !soundType.equals("")) {
play = Manager.createPlayer(new ByteArrayInputStream(data),
soundType);
} else {
play = Manager.createPlayer(new ByteArrayInputStream(data),
this.soundType);
}
play.prefetch();
play.realize();
}
} catch (IOException e) {
e.printStackTrace();
} catch (javax.microedition.media.MediaException e) {
e.printStackTrace();
}
}
public void start() {
try {
if (play != null) {
play.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void stop() {
try {
if (play != null) {
play.stop();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void close() {
try {
if (play != null) {
play.close();
play = null;
System.gc();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean isStop() {
if (play == null || play.getState() != Player.STARTED) {
return true;
} else {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -