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

📄 sound.java

📁 thq 发布的《worms》 motorola 源代码
💻 JAVA
字号:

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.microedition.media.Manager;
import javax.microedition.media.Player;

/*
 * 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 {
	Player play = null;
	String fileName;
	String soundType;
	int agoType = 0;
	String[] sound={"audio/midi","audio/x-wav","audio/vnd.qcelp","application/vnd.smaf"};
	//1:背景音 2:爆炸音 3:拜拜 4:获胜后
	public void getPlayer(int type) {
		switch (type) {
			case 1:
				//fileName = WormsThemeIn;
				//data = wormsTheme;
				fileName = "/WormsTheme.mid";
				soundType = sound[0];
				break;
			case 2:
				//fileName = explosionIn;
				//data = explosion;
				fileName = "/explosion.mmf";
				soundType = sound[3];
				break;
			case 3:
				//fileName = byebyeIn;
				//data = byebye;
				fileName = "/byebye.mmf";
				soundType = sound[3];
				break;
			case 4:
				//fileName = victoryIn;
				//data = victory;
				fileName = "/victory.mmf";
				soundType = sound[3];
				break;
		}
		try {
			if (type != agoType) {
				close();
				agoType = type;
			}
			if (play == null || play.getState() == Player.CLOSED) {
				//play = Manager.createPlayer(fileName,soundType);
				//play = Manager.createPlayer(new ByteArrayInputStream(data),soundType);
				play = Manager.createPlayer(getClass().getResourceAsStream(fileName),soundType);
				play.prefetch();
				play.realize();
				if (type == 1) {
					play.setLoopCount(-1);
				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		} catch (javax.microedition.media.MediaException e) {
			e.printStackTrace();
		}catch (Exception 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.stop();
				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 + -