⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sound.java

📁 应用j2me技术开发的手机游戏
💻 JAVA
字号:
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class Sound implements PlayerListener {
	Player player,playerFight;
	VolumeControl vol;

	public Sound(String path) {
		try {
			InputStream is = getClass().getResourceAsStream(path);
			player = Manager.createPlayer(is, "audio/midi");
			player.realize();
			vol = (VolumeControl) player.getControl("VolumeControl");
			vol.setLevel(50);
			player.setLoopCount(-1);
			player.addPlayerListener(this);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}

	public void playSound() {
		try {
			player.start();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}

	public void playSoundFight() {
		try {
			player.start();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}

	public void stopSound() {
		try {
			player.stop();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}

	public void closeSound() {
		player.close();
	}

	public void turnUp() {
		vol.setLevel((vol.getLevel() + 10) > 100 ? 100 : vol.getLevel() + 10);
	}

	public void turnDown() {
		vol.setLevel((vol.getLevel() - 10) < 0 ? 0 : vol.getLevel() - 10);
	}

	public void playerUpdate(Player arg0, String arg1, Object arg2) {

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -