diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/CDPlayerAction.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/CDPlayerAction.java')
| -rw-r--r-- | NET/worlds/scape/CDPlayerAction.java | 336 |
1 files changed, 336 insertions, 0 deletions
diff --git a/NET/worlds/scape/CDPlayerAction.java b/NET/worlds/scape/CDPlayerAction.java new file mode 100644 index 0000000..ab5a648 --- /dev/null +++ b/NET/worlds/scape/CDPlayerAction.java @@ -0,0 +1,336 @@ +/* */ 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; +/* 46 */ 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; +/* 57 */ private int state = 0; +/* */ +/* */ +/* */ +/* */ private boolean same(String str1, String str2) +/* */ { +/* 63 */ if (str1 == null) { +/* 64 */ if (str2 == null) +/* 65 */ return true; +/* 66 */ return false; +/* */ } +/* 68 */ if (str2 == null) +/* 69 */ return false; +/* 70 */ return str1.equals(str2); +/* */ } +/* */ +/* */ private boolean same(CDPlayerAction other) +/* */ { +/* 75 */ return (other != null) && +/* 76 */ (same(this.artist, other.artist)) && (same(this.title, other.title)) && +/* 77 */ (same(this.hash, other.hash)) && (this.start == other.start) && +/* 78 */ (this.stop == other.stop); +/* */ } +/* */ +/* */ +/* */ public Persister trigger(Event e, Persister seqID) +/* */ { +/* 84 */ return null; +/* */ +/* 86 */ boolean done = false; +/* 87 */ if (seqID == null) +/* 88 */ this.state = 0; +/* 89 */ if (this.state == 0) { +/* 90 */ if ((this.isStopper) && (!same(active))) { +/* 91 */ done = true; +/* 92 */ } else if ((active != null) && (active != this)) { +/* 93 */ active.cancel = true; +/* 94 */ } else if (this.start >= this.stop) { +/* 95 */ done = true; +/* */ } else { +/* 97 */ active = this; +/* 98 */ this.cancel = false; +/* 99 */ Main.register(this); +/* 100 */ this.state = 1; +/* 101 */ Thread t = new Thread(this); +/* 102 */ t.setDaemon(true); +/* 103 */ t.start(); +/* */ } +/* */ } +/* 106 */ else if (this.state == 2) { +/* 107 */ active = null; +/* 108 */ Main.unregister(this); +/* 109 */ done = true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 116 */ return done ? null : this; +/* */ } +/* */ +/* */ public void run() +/* */ { +/* 121 */ if (numDrives == -1) { +/* 122 */ numDrives = getNumDrives(); +/* */ } +/* 124 */ for (int i = 0; i < numDrives;) { +/* */ try { +/* 126 */ CDTrackInfo trackInfo = getTrackList(i); +/* 127 */ String curHash = null; +/* 128 */ if (trackInfo != null) { +/* 129 */ curHash = CDDBHash.hashString(trackInfo); +/* 130 */ if (curHash.equals(this.hash)) { +/* 131 */ play(i); +/* 132 */ break; +/* */ } +/* */ } +/* 135 */ if (this.cancel) { +/* */ break; +/* */ } +/* 124 */ i++; +/* */ } +/* */ catch (IOException localIOException) {} +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 139 */ this.state = 2; +/* */ } +/* */ +/* */ +/* */ public void mainCallback() {} +/* */ +/* */ +/* */ public void terminalCallback() +/* */ { +/* 148 */ this.cancel = true; +/* 149 */ if (this.state == 2) { +/* 150 */ Main.unregister(this); +/* */ } +/* */ } +/* */ +/* */ private void play(int drive) throws IOException { +/* */ int driveID; +/* 156 */ if ((driveID = openDrive(drive)) != 0) { +/* 157 */ playAudio(driveID, this.start, this.stop); +/* 158 */ while (isPlaying(driveID)) { +/* */ try { +/* 160 */ Thread.sleep(1000L); +/* */ } catch (InterruptedException localInterruptedException) {} +/* 162 */ if (this.cancel) { +/* 163 */ stopAudio(driveID); +/* 164 */ break; +/* */ } +/* */ } +/* 167 */ closeDrive(driveID); +/* */ } +/* */ } +/* */ +/* */ public static CDTrackInfo getTrackList(int drive) +/* */ throws IOException +/* */ { +/* 174 */ CDTrackInfo ret = null; +/* 175 */ int driveID; if ((driveID = openDrive(drive)) != 0) { +/* 176 */ ret = getDriveTrackList(driveID); +/* 177 */ closeDrive(driveID); +/* */ } +/* 179 */ return ret; } +/* */ +/* */ public static native int getNumDrives(); +/* */ +/* */ public static native int getDriveLetterOffset(int paramInt); +/* */ +/* */ public static native int openDrive(int paramInt) throws IOException; +/* */ +/* */ public static native void closeDrive(int paramInt) throws IOException; +/* */ +/* */ public static native void checkDrive(int paramInt) throws IOException; +/* */ +/* */ public static native CDTrackInfo getDriveTrackList(int paramInt) throws IOException; +/* */ +/* */ public static native void playAudio(int paramInt1, int paramInt2, int paramInt3) throws IOException; +/* */ +/* */ public static native void stopAudio(int paramInt) throws IOException; +/* */ public static native void pauseAudio(int paramInt) throws IOException; +/* */ public static native void resumeAudio(int paramInt) throws IOException; +/* */ public static native boolean isPlaying(int paramInt) throws IOException; +/* */ public static native int getPosition(int paramInt) throws IOException; +/* */ public static native void setNTAutoPlayCode(int paramInt); +/* */ public static native boolean launchVolumeControlApp(); +/* 202 */ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; +/* 203 */ switch (index - offset) { +/* */ case 0: +/* 205 */ if (mode == 0) { +/* 206 */ ret = StringPropertyEditor.make(new Property(this, index, +/* 207 */ "Artist")); +/* 208 */ } else if (mode == 1) { +/* 209 */ ret = this.artist; +/* 210 */ } else if (mode == 2) +/* 211 */ this.artist = ((String)value); +/* 212 */ break; +/* */ case 1: +/* 214 */ if (mode == 0) { +/* 215 */ ret = StringPropertyEditor.make(new Property(this, index, +/* 216 */ "Title")); +/* 217 */ } else if (mode == 1) { +/* 218 */ ret = this.title; +/* 219 */ } else if (mode == 2) +/* 220 */ this.title = ((String)value); +/* 221 */ break; +/* */ case 2: +/* 223 */ if (mode == 0) { +/* 224 */ ret = StringPropertyEditor.make(new Property(this, index, +/* 225 */ "Disk ID (Edit or Delete to read CD)").allowSetNull()); +/* 226 */ } else if (mode == 1) { +/* 227 */ if (this.hash == null) { +/* */ try { +/* 229 */ CDTrackInfo trackList = getTrackList(0); +/* 230 */ if (trackList != null) +/* 231 */ this.hash = CDDBHash.hashString(trackList); +/* */ } catch (IOException localIOException) {} +/* */ } +/* 234 */ ret = this.hash; +/* */ } +/* 236 */ else if (mode == 2) { +/* 237 */ this.hash = ((String)value); } +/* 238 */ break; +/* */ case 3: +/* 240 */ if (mode == 0) { +/* 241 */ ret = CDPositionPropertyEditor.make(new Property(this, index, +/* 242 */ "Start (75ths of a second)"), +/* 243 */ false); +/* 244 */ } else if (mode == 1) { +/* 245 */ ret = new Integer(this.start); +/* 246 */ } else if (mode == 2) +/* 247 */ this.start = ((Integer)value).intValue(); +/* 248 */ break; +/* */ case 4: +/* 250 */ if (mode == 0) { +/* 251 */ ret = CDPositionPropertyEditor.make(new Property(this, index, +/* 252 */ "Stop (75ths of a second)"), +/* 253 */ true); +/* 254 */ } else if (mode == 1) { +/* 255 */ ret = new Integer(this.stop); +/* 256 */ } else if (mode == 2) +/* 257 */ this.stop = ((Integer)value).intValue(); +/* 258 */ break; +/* */ case 5: +/* 260 */ if (mode == 0) { +/* 261 */ ret = BooleanPropertyEditor.make( +/* 262 */ new Property(this, index, "Stop identical CDPlayerAction"), +/* 263 */ "No", "Yes"); +/* 264 */ } else if (mode == 1) { +/* 265 */ ret = new Boolean(this.isStopper); +/* 266 */ } else if (mode == 2) +/* 267 */ this.isStopper = ((Boolean)value).booleanValue(); +/* 268 */ break; +/* */ +/* */ default: +/* 271 */ ret = super.properties(index, offset + 6, mode, value); +/* */ } +/* 273 */ return ret; +/* */ } +/* */ +/* 276 */ private static Object classCookie = new Object(); +/* */ +/* */ public void saveState(Saver s) throws IOException +/* */ { +/* 280 */ s.saveVersion(2, classCookie); +/* 281 */ super.saveState(s); +/* 282 */ s.saveString(this.artist); +/* 283 */ s.saveString(this.title); +/* 284 */ s.saveString(this.hash); +/* 285 */ s.saveInt(this.start); +/* 286 */ s.saveInt(this.stop); +/* 287 */ s.saveBoolean(this.isStopper); +/* */ } +/* */ +/* */ public void restoreState(Restorer r) throws IOException, TooNewException +/* */ { +/* 292 */ switch (r.restoreVersion(classCookie)) { +/* */ case 1: +/* 294 */ super.restoreState(r); +/* 295 */ this.artist = r.restoreString(); +/* 296 */ this.title = r.restoreString(); +/* 297 */ this.hash = r.restoreString(); +/* 298 */ this.start = r.restoreInt(); +/* 299 */ this.stop = r.restoreInt(); +/* 300 */ break; +/* */ +/* */ case 2: +/* 303 */ super.restoreState(r); +/* 304 */ this.artist = r.restoreString(); +/* 305 */ this.title = r.restoreString(); +/* 306 */ this.hash = r.restoreString(); +/* 307 */ this.start = r.restoreInt(); +/* 308 */ this.stop = r.restoreInt(); +/* 309 */ this.isStopper = r.restoreBoolean(); +/* 310 */ break; +/* */ +/* */ default: +/* 313 */ throw new TooNewException(); +/* */ } +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\CDPlayerAction.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |