1 7 8 package javax.sound.sampled; 9 10 51 public interface DataLine extends Line { 52 53 54 67 public void drain(); 68 69 83 public void flush(); 84 85 97 public void start(); 98 99 115 public void stop(); 116 117 127 public boolean isRunning(); 128 129 143 public boolean isActive(); 144 145 162 public AudioFormat getFormat(); 163 164 174 public int getBufferSize(); 175 176 195 public int available(); 196 197 207 public int getFramePosition(); 208 209 210 218 public long getLongFramePosition(); 219 220 221 232 public long getMicrosecondPosition(); 233 234 244 public float getLevel(); 245 246 267 public static class Info extends Line.Info { 268 269 private AudioFormat [] formats; 270 private int minBufferSize; 271 private int maxBufferSize; 272 273 284 public Info(Class <?> lineClass, AudioFormat [] formats, int minBufferSize, int maxBufferSize) { 285 286 super(lineClass); 287 288 if (formats == null) { 289 this.formats = new AudioFormat [0]; 290 } else { 291 this.formats = formats; 292 } 293 294 this.minBufferSize = minBufferSize; 295 this.maxBufferSize = maxBufferSize; 296 } 297 298 299 309 public Info(Class <?> lineClass, AudioFormat format, int bufferSize) { 310 311 super(lineClass); 312 313 if (format == null) { 314 this.formats = new AudioFormat [0]; 315 } else { 316 AudioFormat [] formats = { format }; 317 this.formats = formats; 318 } 319 320 this.minBufferSize = bufferSize; 321 this.maxBufferSize = bufferSize; 322 } 323 324 325 334 public Info(Class <?> lineClass, AudioFormat format) { 335 this(lineClass, format, AudioSystem.NOT_SPECIFIED); 336 } 337 338 339 359 public AudioFormat [] getFormats() { 360 361 AudioFormat [] returnedArray = new AudioFormat [formats.length]; 362 System.arraycopy(formats, 0, returnedArray, 0, formats.length); 363 return returnedArray; 364 } 365 366 376 public boolean isFormatSupported(AudioFormat format) { 377 378 for (int i = 0; i < formats.length; i++) { 379 if (format.matches(formats[i])) { 380 return true; 381 } 382 } 383 384 return false; 385 } 386 387 391 public int getMinBufferSize() { 392 return minBufferSize; 393 } 394 395 396 400 public int getMaxBufferSize() { 401 return maxBufferSize; 402 } 403 404 405 415 public boolean matches(Line.Info info) { 416 417 if (! (super.matches(info)) ) { 418 return false; 419 } 420 421 Info dataLineInfo = (Info)info; 422 423 if ((getMaxBufferSize() >= 0) && (dataLineInfo.getMaxBufferSize() >= 0)) { 427 if (getMaxBufferSize() > dataLineInfo.getMaxBufferSize()) { 428 return false; 429 } 430 } 431 432 if ((getMinBufferSize() >= 0) && (dataLineInfo.getMinBufferSize() >= 0)) { 433 if (getMinBufferSize() < dataLineInfo.getMinBufferSize()) { 434 return false; 435 } 436 } 437 438 AudioFormat [] localFormats = getFormats(); 439 440 if (localFormats != null) { 441 442 for (int i = 0; i < localFormats.length; i++) { 443 if (! (localFormats[i] == null) ) { 444 if (! (dataLineInfo.isFormatSupported(localFormats[i])) ) { 445 return false; 446 } 447 } 448 } 449 } 450 451 return true; 452 } 453 454 458 public String toString() { 459 460 StringBuffer buf = new StringBuffer (); 461 462 if ( (formats.length == 1) && (formats[0] != null) ) { 463 buf.append(" supporting format " + formats[0]); 464 } else if (getFormats().length > 1) { 465 buf.append(" supporting " + getFormats().length + " audio formats"); 466 } 467 468 if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (maxBufferSize != AudioSystem.NOT_SPECIFIED) ) { 469 buf.append(", and buffers of " + minBufferSize + " to " + maxBufferSize + " bytes"); 470 } else if ( (minBufferSize != AudioSystem.NOT_SPECIFIED) && (minBufferSize > 0) ) { 471 buf.append(", and buffers of at least " + minBufferSize + " bytes"); 472 } else if (maxBufferSize != AudioSystem.NOT_SPECIFIED) { 473 buf.append(", and buffers of up to " + minBufferSize + " bytes"); 474 } 475 476 return new String (super.toString() + buf); 477 } 478 } 480 } | Popular Tags |