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

📄 soundplayer.java

📁 手机游戏设计一书的源代码
💻 JAVA
字号:
import  javax.microedition.midlet.*;import  javax.microedition.lcdui.*;import  javax.microedition.media.*;import  java.io.InputStream;import  java.util.Timer;import  java.util.TimerTask;public class SoundPlayer extends TimerTask {    private Player player;    private String soundFile, soundType;    private Timer m_Timer;/** *  声音播放方法 * @param     String soundFile * @param     String soundType */    public SoundPlayer (String soundFile, String soundType) {        this.soundFile = soundFile;        this.soundType = soundType;        play();        m_Timer = new Timer();        m_Timer.schedule(this, 500L);    }/** * 主要实现方法,在这里添加你的处理代码。 */    public void run () {        if (player.getState() == 300) {            play();        }        m_Timer.schedule(this, 500L);    }    private void play () {        try {            InputStream is = getClass().getResourceAsStream(soundFile);            player = Manager.createPlayer(is, soundType);            player.realize();            player.start();        } catch (MediaException ex) {            ex.printStackTrace();        } catch (Exception ex) {            ex.printStackTrace();        }    }    public void stop () {        m_Timer.cancel();        m_Timer = null;    }}

⌨️ 快捷键说明

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