📄 peffect.java
字号:
//#ifdef S40
//# import com.nokia.mid.sound.Sound;
//# import com.nokia.mid.sound.SoundListener;
//# import com.nokia.mid.ui.DeviceControl;
//#else
import java.io.InputStream;
import javax.microedition.media.*;
//#endif
//================//
// Program body //
//================//
//#ifdef S40
//# class pEffect implements SoundListener {
//# // Sound system variables //
//# private static Sound m_pSound = null;
//# //private static Sound m_pBGSound = null;
//# pEffect() {}
//# // Sound sample data //
//# private final static byte[] TITLE = {
//# (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
//# (byte)0x04, (byte)0x00, (byte)0xc7, (byte)0x1a,
//# (byte)0x83, (byte)0x11, (byte)0x49, (byte)0x1a,
//# (byte)0x90, (byte)0x81, (byte)0x58, (byte)0x91,
//# (byte)0xa9, (byte)0x08, (byte)0x20, (byte)0xc4,
//# (byte)0x52, (byte)0x46, (byte)0xa4, (byte)0x20,
//# (byte)0x4e, (byte)0x25, (byte)0x6a, (byte)0x42,
//# (byte)0x06, (byte)0x22, (byte)0x5a, (byte)0xa5,
//# (byte)0x6a, (byte)0x4e, (byte)0xa4, (byte)0x6a,
//# (byte)0x83, (byte)0x95, (byte)0x35, (byte)0x53,
//# (byte)0x0d, (byte)0x20, (byte)0x82, (byte)0x10,
//# (byte)0x49, (byte)0x68, (byte)0x96, (byte)0xa9,
//# (byte)0x08, (byte)0x13, (byte)0x89, (byte)0x3a,
//# (byte)0x90, (byte)0x82, (byte)0x0e, (byte)0x44,
//# (byte)0xe5, (byte)0x48, (byte)0x40, (byte)0xc4,
//# (byte)0x4c, (byte)0x54, (byte)0x84, (byte)0x0a,
//# (byte)0xb4, (byte)0x84, (byte)0x0b, (byte)0x54,
//# (byte)0xad, (byte)0x4a, (byte)0x54, (byte)0xad,
//# (byte)0x52, (byte)0x45, (byte)0x84, (byte)0x10,
//# (byte)0x41, (byte)0x88, (byte)0x31, (byte)0x14,
//# (byte)0x91, (byte)0xa9, (byte)0x08, (byte)0x15,
//# (byte)0x89, (byte)0x1a, (byte)0x90, (byte)0x82,
//# (byte)0x0c, (byte)0x45, (byte)0x24, (byte)0x6a,
//# (byte)0x42, (byte)0x04, (byte)0xe2, (byte)0x56,
//# (byte)0xa4, (byte)0x20, (byte)0x62, (byte)0x25,
//# (byte)0xaa, (byte)0x56, (byte)0xa4, (byte)0xea,
//# (byte)0x46, (byte)0xa8, (byte)0x39, (byte)0x53,
//# (byte)0x55, (byte)0x30, (byte)0xd2, (byte)0x08,
//# (byte)0x21, (byte)0x04, (byte)0x91, (byte)0x89,
//# (byte)0x18, (byte)0x98, (byte)0x89, (byte)0x88,
//# (byte)0x95, (byte)0x81, (byte)0x08, (byte)0x15,
//# (byte)0xa9, (byte)0x08, (byte)0x18, (byte)0x81,
//# (byte)0x08, (byte)0x18, (byte)0xa9, (byte)0x08,
//# (byte)0x20, (byte)0xc3, (byte)0x48, (byte)0x41,
//# (byte)0x25, (byte)0x9a, (byte)0x56, (byte)0xa4,
//# (byte)0x5a, (byte)0x00
//# };
//#
//# private static final byte[] BOMB = {
//# (byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
//# (byte)0x04, (byte)0x00, (byte)0x0d, (byte)0x18,
//# (byte)0x46, (byte)0x88, (byte)0x35, (byte)0x54,
//# (byte)0x91, (byte)0x88, (byte)0x00
//# };
//#
//# public void soundStateChanged(Sound pSound, int iEvent) {
//# }
//#
//# public void PlaySound(String Filename,boolean isLoop)
//# {
//# if(Filename.equals( "/title.mid" ))
//# {
//# PlaySound(TITLE, 0);
//# }
//# else if(Filename.equals( "/bomb.mid"))
//# {
//# PlaySound(BOMB, 1);
//# }
//# }
//#
//# private void PlaySound(byte[] pSound, int times){
//# try {
//# if (m_pSound == null) {
//# m_pSound = new Sound(pSound, Sound.FORMAT_TONE);
//# m_pSound.setSoundListener(this);
//# m_pSound.setGain(250);
//# }
//# m_pSound.init(pSound, Sound.FORMAT_TONE);
//# m_pSound.play(times);
//# } catch(Exception e) {}
//# }
//#
//# public static void StopSound()
//# {
//# if(m_pSound!=null)
//# {
//# m_pSound.stop();
//# m_pSound = null;
//# }
//# }
//# }
//#else
class pEffect {
private static InputStream m_pInput;
public static Player m_pSFX;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
pEffect() {
}
public static void FreeAll() {
if (m_pSFX != null) {
try {
m_pSFX.stop();
m_pSFX.close();
m_pSFX = null;
} catch (Exception e) {}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
public static void LoadSound(String sFilename) {
try {
m_pInput = "".getClass().getResourceAsStream(sFilename);
if (m_pInput != null ) {
m_pSFX = Manager.createPlayer(m_pInput, "audio/midi");
}
} catch (Exception e) {
System.out.println("[Effect] "+e.toString());
}
}
public static void PlaySound(String Filename,boolean isLoop) {
//System.out.println(Filename);
LoadSound(Filename);
PlaySound((byte)0,isLoop);
}
public static void PlaySound(byte iChannel,boolean isLoop) {
try {
if (m_pSFX != null) {
while( m_pSFX.getState() == 100)
m_pSFX.realize();
while( m_pSFX.getState() == 200)
m_pSFX.prefetch();
if(isLoop)
m_pSFX.setLoopCount(9999);
else
m_pSFX.setLoopCount(1);
m_pSFX.start();
}
} catch (Exception e) {
System.out.println("playsound error");
}
}
public static void StopSound() {
try {
if (m_pSFX != null) {
m_pSFX.stop();
m_pSFX.deallocate();
m_pSFX.close();
m_pSFX = null;
System.gc();
}
} catch (Exception e) {}
}
}
//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -