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

📄 playmedia5.java

📁 基于J2me的手机软件演示例子
💻 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 + -