扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年9月22日
关键字: 手机
在本页阅读全文(共3页)
public void playSound(EMSound sound, int count) {
if (!soundEnable) {
return;
}
try {
if (soundPlaying) {
stopSound();
}
if (soundPlayer == null) {
soundPlayer = Manager.createPlayer(new ByteArrayInputStream(sound.data),
sound.type);
soundPlayer.addPlayerListener(soundListener);
currentSound = null;
}
if (sound != currentSound) {
soundPlayer.close();
soundPlayer = Manager.createPlayer(new ByteArrayInputStream(sound.data),
sound.type);
currentSound = sound;
}
soundPlayer.start();
}
catch (Exception ex) {
soundPlaying = false;
System.out.println(ex.toString());
}
}
public void stopSound() {
if (!soundEnable) {
return;
}
if (soundPlayer != null) {
try {
soundPlayer.stop();
}
catch (Exception e) {
System.out.print(e.toString());
}
}
}
public boolean isSoundPlaying() {
return soundPlaying;
}
public boolean isSoundEnable() {
return soundEnable;
}
3.读取mid文件
1)
import javax.microedition.media.*;
2)
Player player;
void initSound() {
try {
player = Manager.createPlayer(getStream("/sound/b_main.mid"),
"audio/midi");
player.realize();
player.setLoopCount(100000);
}
catch (Exception e) {
e.printStackTrace();
}
}
3) //在程序中对声音的控制
m_playSound = (byte) (1 - m_playSound);
if (m_playSound == 1) {
try {
player.start();
}
catch (Exception e) {}
}
if (m_playSound == 0) {
try {
player.stop();
}
catch (Exception e) {}
}
///---------------end
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。