public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException {
   InputStream inputStream = url.openStream();
   try {
     return getMidiFileFormat(inputStream);
   } finally {
     inputStream.close();
   }
 }
 public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
   InputStream inputStream = new FileInputStream(file);
   // inputStream = new BufferedInputStream(inputStream, 1024);
   try {
     return getMidiFileFormat(inputStream);
   } finally {
     inputStream.close();
   }
 }
示例#3
1
 /**
  * Loads a sequence from an input stream. Returns null if an error occurs.
  *
  * @param is
  * @return
  */
 public Sequence getSequence(InputStream is) {
   try {
     if (!is.markSupported()) {
       is = new BufferedInputStream(is);
     }
     Sequence s = MidiSystem.getSequence(is);
     is.close();
     return s;
   } catch (InvalidMidiDataException ex) {
     ex.printStackTrace();
     return null;
   } catch (IOException ex) {
     ex.printStackTrace();
     return null;
   }
 }
示例#4
1
    public void run() {
      // get line and buffer from ThreadLocals
      SourceDataLine line = (SourceDataLine) localLine.get();
      byte[] buffer = (byte[]) localBuffer.get();
      if (line == null || buffer == null) {
        // the line is unavailable
        return;
      }

      // copy data to the line
      try {
        int numBytesRead = 0;
        while (numBytesRead != -1) {
          // if paused, wait until unpaused
          synchronized (pausedLock) {
            if (paused) {
              try {
                pausedLock.wait();
              } catch (InterruptedException ex) {
                return;
              }
            }
          }
          // copy data
          numBytesRead = source.read(buffer, 0, buffer.length);
          if (numBytesRead != -1) {
            line.write(buffer, 0, numBytesRead);
          }
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
 public Sequence getSequence(URL url) throws InvalidMidiDataException, IOException {
   InputStream inputStream = url.openStream();
   try {
     return getSequence(inputStream);
   } catch (InvalidMidiDataException e) {
     if (TDebug.TraceAllExceptions) {
       TDebug.out(e);
     }
     inputStream.close();
     throw e;
   } catch (IOException e) {
     if (TDebug.TraceAllExceptions) {
       TDebug.out(e);
     }
     inputStream.close();
     throw e;
   }
 }
 public Sequence getSequence(File file) throws InvalidMidiDataException, IOException {
   InputStream inputStream = new FileInputStream(file);
   // inputStream = new BufferedInputStream(inputStream, 1024);
   try {
     return getSequence(inputStream);
   } catch (InvalidMidiDataException e) {
     if (TDebug.TraceAllExceptions) {
       TDebug.out(e);
     }
     inputStream.close();
     throw e;
   } catch (IOException e) {
     if (TDebug.TraceAllExceptions) {
       TDebug.out(e);
     }
     inputStream.close();
     throw e;
   }
 }
示例#7
1
  /** Creates an AudioInputStream from a sound from an input stream */
  public AudioInputStream getAudioInputStream(InputStream is) {

    try {
      if (!is.markSupported()) {
        is = new BufferedInputStream(is);
      }
      // open the source stream
      AudioInputStream source = AudioSystem.getAudioInputStream(is);

      // convert to playback format
      return AudioSystem.getAudioInputStream(playbackFormat, source);
    } catch (UnsupportedAudioFileException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (IllegalArgumentException ex) {
      ex.printStackTrace();
    }

    return null;
  }