📄 source.java
字号:
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
public class Source implements PlayerListener {
Player p;
VolumeControl volC;
Source(String fileName){
InputStream is = getClass().getResourceAsStream(fileName);
if(is == null){
System.out.println("Error creating InputStream " + fileName);
}
try{
p = Manager.createPlayer(is,"audio/X-wav");
if(p == null){
System.out.println("Error creating Player " + fileName);
}
else {
p.addPlayerListener(this);
p.realize();
p.prefetch();
p.setLoopCount(-1);
System.out.println("Realized Player:" + fileName);
}
}
catch(IOException e){
System.out.println(e);
}
catch(MediaException e){
System.out.println(e);
}
volC = (VolumeControl)p.getControl("VolumeControl");
}
public void destroy(){
if(p != null){
p.close();
}
}
public void start(){
if(p != null){
try{
p.start();
}
catch(MediaException e){
System.out.println(e);
}
}
}
public void stop(){
if(p != null && p.getState() == Player.STARTED){
try{
p.stop();
}
catch(MediaException e){
System.out.println(e);
}
}
}
public void rewind(){
if(p != null && p.getState() == Player.PREFETCHED){
try{
p.setMediaTime(-1);
}
catch(MediaException e){
System.out.println(e);
}
}
}
public int setLevel(int level){
return volC.setLevel(level);
}
public void playerUpdate(Player p,String event,Object eventData){
if(event == STARTED)
System.out.println("Player started");
else if(event == STOPPED)
System.out.println("Player stopped");
else if(event == END_OF_MEDIA)
System.out.println("Player at end of file");
else if(event == VOLUME_CHANGED)
System.out.println("Player volume changed");
else if(event == CLOSED)
System.out.println("Player closed");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -