📄 musicplayer.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2005-4-9 12:51:47
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: MusicPlayer.java
package girl60;
// Referenced classes of package AfterDark:
// InstrumentChannel
class MusicPlayer
{
public MusicPlayer(int instrumentNum)
{
isPaused = false;
try
{
channel = new InstrumentChannel[instrumentNum];
}
catch(Exception e)
{
for(int i = 0; i < channel.length; i++)
channel[i] = null;
}
}
public void Pause()
{
synchronized(this)
{
isPaused = true;
}
for(int i = 0; i < channel.length; i++)
if(channel[i] != null)
channel[i].Pause();
}
public void Resume()
{
synchronized(this)
{
isPaused = false;
}
for(int i = 0; i < channel.length; i++)
if(channel[i] != null)
channel[i].Resume();
}
public void SetTune(int chNum, String string, int soundFormat)
{
try
{
channel[chNum] = new InstrumentChannel(ConvertHexToBinary(string), soundFormat);
}
catch(Exception e) { }
}
public int GetInstrumentNumber(int chNum, String string)
{
return channel.length;
}
public void SetVolume(int level)
{
for(int i = 0; i < channel.length; i++)
channel[i].SetVolume(level);
}
public int GetVolume(int chNum)
{
return channel[chNum].GetVolume();
}
public void Play(int chId, int loop)
{
if(channel[chId] != null)
{
channel[chId].Stop();
channel[chId].Play(loop);
}
}
public void Stop(int chId)
{
if(channel[chId] != null)
channel[chId].Stop();
}
private static byte[] ConvertHexToBinary(String hexData)
throws Exception
{
if(hexData.length() % 2 != 0)
throw new Exception("Must be an even number of hex digits");
byte binaryData[] = new byte[hexData.length() / 2];
for(int i = 0; i < binaryData.length; i++)
{
String byteStr = hexData.substring(i * 2, i * 2 + 2);
if(byteStr.charAt(0) == '-')
throw new Exception("Invalid hex digit: -");
int value;
try
{
value = Integer.parseInt(byteStr, 16);
}
catch(NumberFormatException e)
{
throw new Exception("Invalid hex digits: " + byteStr);
}
binaryData[i] = (byte)value;
}
return binaryData;
}
static final int FORMAT_TONE = 1;
private volatile boolean isPaused;
private InstrumentChannel channel[];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -