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

📄 main.java

📁 简单的声音播放程序演示示例(doja开发环境)
💻 JAVA
字号:
import java.io.InputStream;

import javax.microedition.io.Connector;

import com.nttdocomo.io.ConnectionException;
import com.nttdocomo.io.HttpConnection;
import com.nttdocomo.opt.ui.AudioPresenter2;
import com.nttdocomo.ui.*;
import com.nttdocomo.util.EventListener;

public class Main extends IApplication {

	public void start() {

		// Create canvas
		MyCanvas myCanvas = new MyCanvas();
		Display.setCurrent(myCanvas);
	}
}

class MyCanvas extends Canvas {

	// Player component
	AudioPresenter ap;

	// Sound file
	MediaSound ms;

	// Sound volume
	int volume = 80;

	public MyCanvas() {

		// Make two soft keys
		setSoftLabel(SOFT_KEY_1, "Play");
		setSoftLabel(SOFT_KEY_2, "Stop");

		try {

			// Init sound file and set player
			ms = MediaManager.getSound("resource:///BGM3.mld");
			ms.use();

			ap = AudioPresenter.getAudioPresenter();
			ap.setSound(ms);
			ap.setAttribute(AudioPresenter.SET_VOLUME, volume);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void paint(Graphics g) {

		// Clear screen (paint it in white)
		g.setColor(Graphics.getColorOfName(Graphics.WHITE));
		g.fillRect(0, 0, getWidth(), getHeight());

		// Set black color to print text
		g.setColor(Graphics.getColorOfName(Graphics.BLACK));

		// Print message with current sound volume
		g.drawString("Volume = " + volume + "%", 40, 40);
	}

	// Soft keys for play and stop
	public void processEvent(int type, int param) {

		if (type == Display.KEY_PRESSED_EVENT) {

			// Play from start
			if (param == Display.KEY_SOFT1) {

				// If player is not stopped, first stop it and play again
				if (ap != null) {
					ap.stop();
					ap.play();
				}
			}

			// Stop
			else if (param == Display.KEY_SOFT2) {
				ap.stop();

			// Increase volume for 10% (must not be more than 100%)
			} else if (param == Display.KEY_UP) {
				if (volume <= 90) {
					volume += 10;
					ap.setAttribute(AudioPresenter.SET_VOLUME, volume);

					// Printout message
					repaint();
				}

			// Decrease volume for 10% (must not be less than 0%)
			} else if (param == Display.KEY_DOWN) {
				if (volume >= 10) {
					volume -= 10;
					ap.setAttribute(AudioPresenter.SET_VOLUME, volume);

					// Printout message
					repaint();
				}
			}
		}
	}
}

⌨️ 快捷键说明

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