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

📄 sound.java

📁 是基于J2ME的一个模拟手机的界面可以实现手机收发短信基于客户端和服务器端的功能
💻 JAVA
字号:
package phone.mediaSound.play;

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

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Ticker;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

import phone.MediaSound;

public class Sound extends List implements CommandListener {

	private Display display;

	private Command cmdCancel, cmdOk, cmdStop, cmdBack;

	private MediaSound ms;

	private Player player;

	private Ticker ticker;

	private Form form;

	public Sound(MediaSound ms, Display display) {
		super("贝多芬钢琴曲", List.IMPLICIT);
		this.ms = ms;
		this.display = display;

		this.append("第三交响曲", null);
		this.append("热情奏鸣曲", null);
		this.append("热情奏鸣曲", null);

		cmdCancel = new Command("cancel", Command.CANCEL, 1);
		cmdOk = new Command("播放", Command.OK, 1);
		this.addCommand(cmdCancel);
		this.addCommand(cmdOk);
		this.setCommandListener(this);

		form = new Form("");

		cmdStop = new Command("stop", Command.STOP, 1);
		cmdBack = new Command("返回", Command.BACK, 1);

		form.addCommand(cmdStop);
		form.addCommand(cmdBack);
		form.setCommandListener(this);
	}

	public void commandAction(Command command, Displayable dis) {
		if (command == cmdStop) {
			try {
				player.stop();
				player.close();
			} catch (MediaException e) {
				e.printStackTrace();
			}
			display.setCurrent(this);
		}
		if (command == cmdBack) {
			try {
				player.stop();
				player.close();
			} catch (MediaException e) {
				e.printStackTrace();
			}
			display.setCurrent(this);
		}
		if (command == cmdOk) {
			int select = this.getSelectedIndex();
			if (select == 0) {
				ticker = new Ticker("贝多芬.第三交响曲.mid");
				form.setTicker(ticker);
				display.setCurrent(form);
				InputStream is = this.getClass().getResourceAsStream(
						"/phone/mediaSound/play/musics/1.mid");
				try {
					player = Manager.createPlayer(is, "audio/midi");
					player.realize();
					player.start();
				} catch (IOException e) {
					e.printStackTrace();
				} catch (MediaException e) {
					e.printStackTrace();
				}
			}
			if (select == 1) {
				ticker = new Ticker("贝多芬.热情奏鸣曲.mid");
				form.setTicker(ticker);
				display.setCurrent(form);
				InputStream is = this.getClass().getResourceAsStream(
						"/phone/mediaSound/play/musics/2.mid");
				try {
					player = Manager.createPlayer(is, "audio/midi");
					player.realize();
					player.start();
				} catch (IOException e) {
					e.printStackTrace();
				} catch (MediaException e) {
					e.printStackTrace();
				}
			}
			if (select == 2) {
				ticker = new Ticker("贝多芬.献给爱丽丝二");
				form.setTicker(ticker);
				display.setCurrent(form);
				InputStream is = this.getClass().getResourceAsStream(
						"/phone/mediaSound/play/musics/3.mid");
				try {
					player = Manager.createPlayer(is, "audio/midi");
					player.realize();
					player.start();
				} catch (IOException e) {
					e.printStackTrace();
				} catch (MediaException e) {
					e.printStackTrace();
				}
			}
		}
		if (command == cmdCancel) {
			ms.getMediaSound();
		}

	}

}

⌨️ 快捷键说明

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