📄 sound.java
字号:
/*
* Created on 2005-11-16 by pcy
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.nokia.mid.sound;
import javax.microedition.media.*;
import java.io.*;
public class Sound {
public static final int FORMAT_TONE=1;
public static final int FORMAT_WAVE=5;
public static final int SOUND_PLAYING=0;
public static final int SOUND_STOPPED=1;
public static final int SOUND_UNINITIALIZEDSound=3;
private Player player;
private int state;
private int gain;
private SoundListener listener;
private int freq;
private int dur;
private boolean playFreq;
public Sound(byte[] data, int type){
init(data,type);
}
public Sound(int freq, long duration){
init(freq,duration);
}
public void init(int freq, long duration){
/*release();
this.freq=freq;
dur=(int)duration;
playFreq=true;*/
}
public void init(byte[] data, int type){
/*release();
if(data==null){
throw new NullPointerException();
}
String stype="";
if(type==FORMAT_TONE){
stype="audio/x-tone-seq";
}else if(type==FORMAT_WAVE){
stype="audio/x-wav";
}else{
throw new java.lang.IllegalArgumentException();
}
try{
player=Manager.createPlayer(new ByteArrayInputStream(data),stype);
}catch(Exception e){
throw new java.lang.IllegalArgumentException() ;
}
state=SOUND_STOPPED;
playFreq=false;*/
}
public void play(int loop){
/*if(loop<0){
throw new IllegalArgumentException();
}else if(loop>255){
return;
}
if(playFreq){
int lp=loop;
try{
fireEvt(SOUND_PLAYING);
while(lp>0||loop==0){
Manager.playTone(freq,dur,gain);
}
}catch(Exception e){
e.printStackTrace();
}
}else if(player!=null){
try{
if(player.getState()==Player.STARTED){
player.stop();
}
if(loop==0){
loop=-1;
}
player.setLoopCount(loop);
fireEvt(SOUND_PLAYING);
player.start();
}catch(Exception e){
e.printStackTrace();
}
}else{
throw new IllegalArgumentException();
}*/
}
public void stop(){
/*if(state==SOUND_PLAYING){
if(!playFreq&&player!=null){
try{
player.stop();
}catch(Exception e){
e.printStackTrace();
}
}
fireEvt(SOUND_STOPPED);
}*/
}
public void resume(){
/*if(!playFreq&&player!=null){
try{
player.start();
}catch(Exception e){
e.printStackTrace();
}
}*/
}
public void release(){
/*if(player!=null){
player.close();
player=null;
}
playFreq=false;*/
}
public void setGain(int gain){
this.gain=gain;
}
public int getGain(){
return gain;
}
public int getState(){
return state;
}
public static int getConcurrentSoundCount(int type){
if(type==FORMAT_TONE){
return 1;
}else if(type==FORMAT_WAVE){
return 3;
}else{
throw new java.lang.IllegalArgumentException();
}
}
public static int[] getSupportedFormats(){
int fmt[]=new int[2];
fmt[0]=FORMAT_TONE;
fmt[1]=FORMAT_WAVE;
return fmt;
}
public void setSoundListener(SoundListener listener){
this.listener=listener;
}
private void fireEvt(int event){
state=event;
if(listener!=null){
listener.soundStateChanged(this,event);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -