📄 sound.java
字号:
import java.io.*;
import javax.microedition.media.*;
public class Sound
{
private InputStream in=null; //声音文件读入
private InputStream in1=null;
public Player player=null;
public Player player1=null;
//构造函数
public Sound()
{
super();
//调入声音文件
try
{
try
{
in= getClass().getResourceAsStream("/DanceNow.mid");
in1 = getClass().getResourceAsStream("/title.mid");
//播放器
player= Manager.createPlayer(in,"audio/midi");
player1=Manager.createPlayer(in1,"audio/midi");
}
catch(MediaException me)
{System.out.println("MediaException me");}
}
catch(IOException e){System.out.println("no Music file!!!");}
}
//播放
public void play_music()
{
try
{
player.start();
}
catch(MediaException me)
{
System.out.println("////////////////////");
}
}
public void play_music1()
{
try
{
player1.start();
}
catch(MediaException me)
{
System.out.println("////////////////////");
}
}
public void STOP()//声音的停止
{
try
{
player.stop();
}
catch(MediaException me)
{
System.out.println("\\\\\\\\\\\\\\\\\\\\");
}
}
public void STOP1()//声音的停止
{
try
{
player1.stop();
}
catch(MediaException me)
{
System.out.println("\\\\\\\\\\\\\\\\\\\\");
}
}
//关闭
protected void close()
{
if (player != null)
{
player.close();
player = null;
}
if (in != null)
{
try
{
in.close();
}
catch (Exception e)
{
}
in = null;
}
System.gc();
}
protected void close1()
{
if (player1 != null)
{
player1.close();
player1 = null;
}
if (in1 != null)
{
try
{
in1.close();
}
catch (Exception e)
{
}
in1 = null;
}
System.gc();
}
}
//Player.setLootCount()设置播放次数,-1无限,不能为0,1一次,2二次
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -