summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/CDPlayerAction.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/CDPlayerAction.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/CDPlayerAction.java')
-rw-r--r--NET/worlds/scape/CDPlayerAction.java258
1 files changed, 258 insertions, 0 deletions
diff --git a/NET/worlds/scape/CDPlayerAction.java b/NET/worlds/scape/CDPlayerAction.java
new file mode 100644
index 0000000..0d1955a
--- /dev/null
+++ b/NET/worlds/scape/CDPlayerAction.java
@@ -0,0 +1,258 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Main;
+import NET.worlds.console.MainCallback;
+import NET.worlds.console.MainTerminalCallback;
+import java.io.IOException;
+
+public class CDPlayerAction extends Action implements Runnable, MainCallback, MainTerminalCallback {
+ private static final boolean DISABLE_ALL = true;
+ private static final int STATE_INITIAL = 0;
+ private static final int STATE_WAITING = 1;
+ private static final int STATE_DONE = 2;
+ private static int numDrives = -1;
+ private static CDPlayerAction active;
+ private String artist;
+ private String title;
+ private String hash;
+ private int start;
+ private int stop;
+ private boolean isStopper;
+ private boolean cancel;
+ private int state = 0;
+ private static Object classCookie = new Object();
+
+ private boolean same(String str1, String str2) {
+ if (str1 == null) {
+ return str2 == null;
+ } else {
+ return str2 == null ? false : str1.equals(str2);
+ }
+ }
+
+ private boolean same(CDPlayerAction other) {
+ return other != null
+ && this.same(this.artist, other.artist)
+ && this.same(this.title, other.title)
+ && this.same(this.hash, other.hash)
+ && this.start == other.start
+ && this.stop == other.stop;
+ }
+
+ @Override
+ public Persister trigger(Event e, Persister seqID) {
+ return null;
+ }
+
+ @Override
+ public void run() {
+ if (numDrives == -1) {
+ numDrives = getNumDrives();
+ }
+
+ for (int i = 0; i < numDrives; i++) {
+ try {
+ CDTrackInfo trackInfo = getTrackList(i);
+ String curHash = null;
+ if (trackInfo != null) {
+ curHash = CDDBHash.hashString(trackInfo);
+ if (curHash.equals(this.hash)) {
+ this.play(i);
+ break;
+ }
+ }
+
+ if (this.cancel) {
+ break;
+ }
+ } catch (IOException var4) {
+ }
+ }
+
+ this.state = 2;
+ }
+
+ @Override
+ public void mainCallback() {
+ }
+
+ @Override
+ public void terminalCallback() {
+ this.cancel = true;
+ if (this.state == 2) {
+ Main.unregister(this);
+ }
+ }
+
+ private void play(int drive) throws IOException {
+ int driveID;
+ if ((driveID = openDrive(drive)) != 0) {
+ playAudio(driveID, this.start, this.stop);
+
+ while (isPlaying(driveID)) {
+ try {
+ Thread.sleep(1000L);
+ } catch (InterruptedException var4) {
+ }
+
+ if (this.cancel) {
+ stopAudio(driveID);
+ break;
+ }
+ }
+
+ closeDrive(driveID);
+ }
+ }
+
+ public static CDTrackInfo getTrackList(int drive) throws IOException {
+ CDTrackInfo ret = null;
+ int driveID;
+ if ((driveID = openDrive(drive)) != 0) {
+ ret = getDriveTrackList(driveID);
+ closeDrive(driveID);
+ }
+
+ return ret;
+ }
+
+ public static native int getNumDrives();
+
+ public static native int getDriveLetterOffset(int var0);
+
+ public static native int openDrive(int var0) throws IOException;
+
+ public static native void closeDrive(int var0) throws IOException;
+
+ public static native void checkDrive(int var0) throws IOException;
+
+ public static native CDTrackInfo getDriveTrackList(int var0) throws IOException;
+
+ public static native void playAudio(int var0, int var1, int var2) throws IOException;
+
+ public static native void stopAudio(int var0) throws IOException;
+
+ public static native void pauseAudio(int var0) throws IOException;
+
+ public static native void resumeAudio(int var0) throws IOException;
+
+ public static native boolean isPlaying(int var0) throws IOException;
+
+ public static native int getPosition(int var0) throws IOException;
+
+ public static native void setNTAutoPlayCode(int var0);
+
+ public static native boolean launchVolumeControlApp();
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "Artist"));
+ } else if (mode == 1) {
+ ret = this.artist;
+ } else if (mode == 2) {
+ this.artist = (String)value;
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "Title"));
+ } else if (mode == 1) {
+ ret = this.title;
+ } else if (mode == 2) {
+ this.title = (String)value;
+ }
+ break;
+ case 2:
+ if (mode == 0) {
+ ret = StringPropertyEditor.make(new Property(this, index, "Disk ID (Edit or Delete to read CD)").allowSetNull());
+ } else if (mode == 1) {
+ if (this.hash == null) {
+ try {
+ CDTrackInfo trackList = getTrackList(0);
+ if (trackList != null) {
+ this.hash = CDDBHash.hashString(trackList);
+ }
+ } catch (IOException var7) {
+ }
+ }
+
+ ret = this.hash;
+ } else if (mode == 2) {
+ this.hash = (String)value;
+ }
+ break;
+ case 3:
+ if (mode == 0) {
+ ret = CDPositionPropertyEditor.make(new Property(this, index, "Start (75ths of a second)"), false);
+ } else if (mode == 1) {
+ ret = new Integer(this.start);
+ } else if (mode == 2) {
+ this.start = (Integer)value;
+ }
+ break;
+ case 4:
+ if (mode == 0) {
+ ret = CDPositionPropertyEditor.make(new Property(this, index, "Stop (75ths of a second)"), true);
+ } else if (mode == 1) {
+ ret = new Integer(this.stop);
+ } else if (mode == 2) {
+ this.stop = (Integer)value;
+ }
+ break;
+ case 5:
+ if (mode == 0) {
+ ret = BooleanPropertyEditor.make(new Property(this, index, "Stop identical CDPlayerAction"), "No", "Yes");
+ } else if (mode == 1) {
+ ret = new Boolean(this.isStopper);
+ } else if (mode == 2) {
+ this.isStopper = (Boolean)value;
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 6, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(2, classCookie);
+ super.saveState(s);
+ s.saveString(this.artist);
+ s.saveString(this.title);
+ s.saveString(this.hash);
+ s.saveInt(this.start);
+ s.saveInt(this.stop);
+ s.saveBoolean(this.isStopper);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 1:
+ super.restoreState(r);
+ this.artist = r.restoreString();
+ this.title = r.restoreString();
+ this.hash = r.restoreString();
+ this.start = r.restoreInt();
+ this.stop = r.restoreInt();
+ break;
+ case 2:
+ super.restoreState(r);
+ this.artist = r.restoreString();
+ this.title = r.restoreString();
+ this.hash = r.restoreString();
+ this.start = r.restoreInt();
+ this.stop = r.restoreInt();
+ this.isStopper = r.restoreBoolean();
+ break;
+ default:
+ throw new TooNewException();
+ }
+ }
+}