Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r8419 r8510 29 29 30 30 private enum State { INITIALIZING, NOTPLAYING, PLAYING, PAUSED, INTERRUPTED } 31 32 private enum Command { PLAY, PAUSE } 33 34 private enum Result { WAITING, OK, FAILED } 35 31 36 private State state; 32 private enum Command { PLAY, PAUSE }33 private enum Result { WAITING, OK, FAILED }34 37 private URL playingUrl; 35 38 private double leadIn; // seconds … … 62 65 send(); 63 66 } 67 64 68 protected void pause() throws Exception { 65 69 command = Command.PAUSE; 66 70 send(); 67 71 } 72 68 73 private void send() throws Exception { 69 74 result = Result.WAITING; … … 75 80 throw exception; 76 81 } 82 77 83 private void possiblyInterrupt() throws InterruptedException { 78 84 if (interrupted() || result == Result.WAITING) 79 85 throw new InterruptedException(); 80 86 } 87 81 88 protected void failed(Exception e) { 82 89 exception = e; … … 84 91 state = State.NOTPLAYING; 85 92 } 93 86 94 protected void ok(State newState) { 87 95 result = Result.OK; 88 96 state = newState; 89 97 } 98 90 99 protected double offset() { 91 100 return offset; 92 101 } 102 93 103 protected double speed() { 94 104 return speed; 95 105 } 106 96 107 protected URL url() { 97 108 return url; 98 109 } 110 99 111 protected Command command() { 100 112 return command; … … 202 214 */ 203 215 public static void reset() { 204 if (audioPlayer != null) {216 if (audioPlayer != null) { 205 217 try { 206 218 pause(); 207 } catch (Exception e) {219 } catch (Exception e) { 208 220 Main.warn(e); 209 221 } … … 235 247 SourceDataLine audioOutputLine = null; 236 248 AudioFormat audioFormat = null; 237 byte[] abData = new byte[(int) chunk];249 byte[] abData = new byte[(int) chunk]; 238 250 239 251 for (;;) { … … 250 262 case PLAYING: 251 263 command.possiblyInterrupt(); 252 for (;;) {264 for (;;) { 253 265 int nBytesRead = 0; 254 266 nBytesRead = audioInputStream.read(abData, 0, abData.length); … … 301 313 } 302 314 if (calibratedOffset > 0.0) { 303 long bytesToSkip = (long)( 304 calibratedOffset /* seconds (double) */ * bytesPerSecond); 305 /* skip doesn't seem to want to skip big chunks, so 306 * reduce it to smaller ones 307 */ 315 long bytesToSkip = (long) (calibratedOffset /* seconds (double) */ * bytesPerSecond); 316 // skip doesn't seem to want to skip big chunks, so reduce it to smaller ones 308 317 // audioInputStream.skip(bytesToSkip); 309 318 while (bytesToSkip > chunk) { … … 361 370 public static void audioMalfunction(Exception ex) { 362 371 String msg = ex.getMessage(); 363 if (msg == null)372 if (msg == null) 364 373 msg = tr("unspecified reason"); 365 374 else
Note:
See TracChangeset
for help on using the changeset viewer.