📄 playmedia5.java
字号:
package com.wy.ch12;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
public class PlayMedia5 extends MIDlet implements CommandListener,ItemStateListener{
private Display display;
private Form f;
private Gauge gauge;
private Command command;
private VolumeControl vc;
public PlayMedia5(){
display = Display.getDisplay(this);
f = new Form("音乐播放测试");
command = new Command("播放", Command.ITEM, 1);
f.addCommand(command);
gauge=new Gauge("音量控制", true, 10, 5);
f.append(gauge);
gauge.setLayout(Item.LAYOUT_CENTER);
f.setCommandListener(this);
f.setItemStateListener(this);
}
public void startApp() {
display.setCurrent(f);
}
public void commandAction(Command command, Displayable displayable){
try {
InputStream is = getClass().getResourceAsStream("/test-wav.wav");
Player p = Manager.createPlayer(is, "audio/X-wav");
p.realize();
vc=(VolumeControl)p.getControl("VolumeControl");
p.setLoopCount(-1);
vc.setLevel(50);
p.start();
} catch (Exception e){
}
}
public void itemStateChanged(Item item){
int volume=gauge.getValue()*10;
if(vc!=null){
vc.setLevel(volume);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -