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

📄 audioalert.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
字号:
package mujmail.ui;/*MujMail - Simple mail client for J2MECopyright (C) 2005 Pavel Machek <pavel@ucw.cz>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */import java.io.*;/** * Provides functions to play audio alerts. *  * @author Pavel Machek */public class AudioAlert extends Object implements Runnable {    static long lastRun;    /**     * Creates the instance of calss AudioAlert.     */    public AudioAlert() {        synchronized (this) {            //don't play anything in a short time at all, it may crash Java :)            if (System.currentTimeMillis() - lastRun <= 5000) {                return;            }            lastRun = System.currentTimeMillis();        }        new Thread(this).start();    }    /**     * Plays alert using wav format.     */    public void wav() {        /* Unfortunately, this does not seem to work on 6230 */        InputStream is = getClass().getResourceAsStream("/sounds/newmail.wav");        System.out.println(is);        String ctype = "audio/x-wav";        try {            javax.microedition.media.Player player =                    javax.microedition.media.Manager.createPlayer(is, ctype);            player.realize();            player.start();        } catch (Exception ex) {            System.out.println("could not play wav");        }    }    /**     * Plays alert using midi audio format.     */    public void midi() {        /* Works ok on both k700i and 6230 */        InputStream is = getClass().getResourceAsStream("/sounds/newmail.mid");        System.out.println(is);        String ctype = "audio/midi";        try {            javax.microedition.media.Player player =                    javax.microedition.media.Manager.createPlayer(is, ctype);            player.realize();            player.start();        } catch (Exception ex) {            System.out.println("could not play midi");        }    }    /**     * Plays alert using mp3 audio format.     */    public void mp3() {        InputStream is = getClass().getResourceAsStream("/sounds/newmail.mp3");        System.out.println(is);        String ctype = "audio/mpeg";        try {            javax.microedition.media.Player player =                    javax.microedition.media.Manager.createPlayer(is, ctype);            player.realize();            player.start();        } catch (Exception ex) {            System.out.println("could not play mp3");        }    }    /**     * Plays alert using tone.     */    public void tone() {        try {            javax.microedition.media.Manager.playTone(60, 200, 90);            Thread.sleep(200);            javax.microedition.media.Manager.playTone(70, 200, 90);            Thread.sleep(200);            javax.microedition.media.Manager.playTone(60, 200, 90);        } catch (Exception ex) {            System.out.println("could not play tone");        }    }    public void run() {        midi();    }}

⌨️ 快捷键说明

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