Ejemplo n.º 1
0
  private static Line getLine(String propName, Line.Info info) throws LineUnavailableException {

    List<?> mixerProviders = ProviderService.getProviders(mixerProviderPath);

    if (propName != null) {
      String propVal = System.getProperty(propName);
      if (propVal != null) {
        Mixer m = getMixer(propVal, info, mixerProviders);
        if (m != null) {
          Line l = m.getLine(info);
          if (l != null) {
            return l;
          }
        }
      }

      Properties soundProperties = ProviderService.getSoundProperties();
      propVal = soundProperties.getProperty(propName);
      if (propVal != null) {
        Mixer m = getMixer(propVal, info, mixerProviders);
        if (m != null) {
          Line l = m.getLine(info);
          if (l != null) {
            return l;
          }
        }
      }
    }

    for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        MixerProvider pr = (MixerProvider) (providers.next());
        Mixer.Info[] mixinfos = pr.getMixerInfo();
        for (Mixer.Info mixinfo : mixinfos) {
          try {
            Mixer mix = pr.getMixer(mixinfo);
            return mix.getLine(info);
          } catch (IllegalArgumentException e) {
            // continue
          }
        }
      } catch (ClassCastException e) {
      }
    }
    // sound.11=Could not get line
    throw new IllegalArgumentException(Messages.getString("sound.11")); // $NON-NLS-1$
  }
Ejemplo n.º 2
0
  public static boolean isFileTypeSupported(AudioFileFormat.Type fileType) {

    for (Iterator providers = ProviderService.getProviders(audioFileWriterPath).iterator();
        providers.hasNext(); ) {
      if (((AudioFileWriter) (providers.next())).isFileTypeSupported(fileType)) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 3
0
  public static boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat) {

    for (Iterator providers = ProviderService.getProviders(formatConversionProviderPath).iterator();
        providers.hasNext(); ) {
      if (((FormatConversionProvider) (providers.next()))
          .isConversionSupported(targetFormat, sourceFormat)) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 4
0
 public static int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out)
     throws IOException {
   AudioFileWriter writer;
   for (Iterator providers = ProviderService.getProviders(audioFileWriterPath).iterator();
       providers.hasNext(); ) {
     writer = (AudioFileWriter) (providers.next());
     if (writer.isFileTypeSupported(fileType, stream)) {
       return writer.write(stream, fileType, out);
     }
   }
   // sound.18=Type is not supported
   throw new IllegalArgumentException(Messages.getString("sound.18")); // $NON-NLS-1$
 }
Ejemplo n.º 5
0
  public static AudioInputStream getAudioInputStream(File file)
      throws UnsupportedAudioFileException, IOException {

    for (Iterator providers = ProviderService.getProviders(audioFileReaderPath).iterator();
        providers.hasNext(); ) {
      try {
        return ((AudioFileReader) (providers.next())).getAudioInputStream(file);
      } catch (ClassCastException e) {
      } catch (UnsupportedAudioFileException e) {
      }
    }
    // sound.17=Could not get audio input stream from input file
    throw new UnsupportedAudioFileException(Messages.getString("sound.17")); // $NON-NLS-1$
  }
Ejemplo n.º 6
0
  public static AudioFileFormat getAudioFileFormat(File file)
      throws UnsupportedAudioFileException, IOException {

    for (Iterator providers = ProviderService.getProviders(audioFileReaderPath).iterator();
        providers.hasNext(); ) {
      try {
        return ((AudioFileReader) (providers.next())).getAudioFileFormat(file);
      } catch (ClassCastException e) {
      } catch (UnsupportedAudioFileException e) {
      }
    }
    // sound.14=File is not a supported file type
    throw new UnsupportedAudioFileException(Messages.getString("sound.14")); // $NON-NLS-1$
  }
Ejemplo n.º 7
0
 public static Mixer.Info[] getMixerInfo() {
   List<Mixer.Info> result = new ArrayList<Mixer.Info>();
   for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
       providers.hasNext(); ) {
     try {
       Mixer.Info[] infos = ((MixerProvider) (providers.next())).getMixerInfo();
       for (Mixer.Info info : infos) {
         result.add(info);
       }
     } catch (ClassCastException e) {
     }
   }
   Mixer.Info[] temp = new Mixer.Info[result.size()];
   return result.toArray(temp);
 }
Ejemplo n.º 8
0
 public static AudioFileFormat.Type[] getAudioFileTypes() {
   List<AudioFileFormat.Type> result = new ArrayList<AudioFileFormat.Type>();
   for (Iterator providers = ProviderService.getProviders(audioFileWriterPath).iterator();
       providers.hasNext(); ) {
     try {
       AudioFileFormat.Type[] types = ((AudioFileWriter) (providers.next())).getAudioFileTypes();
       for (AudioFileFormat.Type type : types) {
         result.add(type);
       }
     } catch (ClassCastException e) {
     }
   }
   AudioFileFormat.Type[] temp = new AudioFileFormat.Type[result.size()];
   return result.toArray(temp);
 }
Ejemplo n.º 9
0
  public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat) {

    List<AudioFormat.Encoding> result = new ArrayList<AudioFormat.Encoding>();
    for (Iterator providers = ProviderService.getProviders(formatConversionProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        AudioFormat.Encoding[] encodings =
            ((FormatConversionProvider) (providers.next())).getTargetEncodings(sourceFormat);
        for (AudioFormat.Encoding encoding : encodings) {
          result.add(encoding);
        }
      } catch (ClassCastException e) {
      }
    }
    AudioFormat.Encoding[] temp = new AudioFormat.Encoding[result.size()];
    return result.toArray(temp);
  }
Ejemplo n.º 10
0
  public static AudioInputStream getAudioInputStream(
      AudioFormat targetFormat, AudioInputStream sourceStream) {

    if (sourceStream.getFormat().matches(targetFormat)) {
      return sourceStream;
    }
    for (Iterator providers = ProviderService.getProviders(formatConversionProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        return ((FormatConversionProvider) (providers.next()))
            .getAudioInputStream(targetFormat, sourceStream);
      } catch (ClassCastException e) {
      } catch (IllegalArgumentException e) {
      }
    }
    // sound.13=Could not get audio input stream from source stream
    throw new IllegalArgumentException(Messages.getString("sound.13")); // $NON-NLS-1$
  }
Ejemplo n.º 11
0
  public static boolean isLineSupported(Line.Info info) {

    for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        MixerProvider pr = (MixerProvider) providers.next();
        Mixer.Info[] mixinfos = pr.getMixerInfo();
        for (Mixer.Info mixinfo : mixinfos) {
          Mixer mix = pr.getMixer(mixinfo);
          if (mix.isLineSupported(info)) {
            return true;
          }
        }
      } catch (ClassCastException e) {
      }
    }
    return false;
  }
Ejemplo n.º 12
0
  public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sourceEncoding) {

    List<AudioFormat.Encoding> result = new ArrayList<AudioFormat.Encoding>();
    for (Iterator providers = ProviderService.getProviders(formatConversionProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        FormatConversionProvider pr = (FormatConversionProvider) providers.next();
        if (!pr.isSourceEncodingSupported(sourceEncoding)) {
          continue;
        }
        AudioFormat.Encoding[] encodings = pr.getTargetEncodings();
        for (AudioFormat.Encoding encoding : encodings) {
          result.add(encoding);
        }
      } catch (ClassCastException e) {
      }
    }
    AudioFormat.Encoding[] temp = new AudioFormat.Encoding[result.size()];
    return result.toArray(temp);
  }
Ejemplo n.º 13
0
 public static Line.Info[] getTargetLineInfo(Line.Info info) {
   List<Line.Info> result = new ArrayList<Line.Info>();
   for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
       providers.hasNext(); ) {
     try {
       MixerProvider pr = (MixerProvider) providers.next();
       Mixer.Info[] mixinfos = pr.getMixerInfo();
       for (Mixer.Info mixinfo : mixinfos) {
         Mixer mix = pr.getMixer(mixinfo);
         Line.Info[] linfos = mix.getTargetLineInfo(info);
         for (Line.Info linfo : linfos) {
           result.add(linfo);
         }
       }
     } catch (ClassCastException e) {
     }
   }
   Line.Info[] temp = new Line.Info[result.size()];
   return result.toArray(temp);
 }
Ejemplo n.º 14
0
  public static Mixer getMixer(Mixer.Info info) {
    Mixer.Info[] infos;
    Mixer.Info inf;
    if (info == null) {
      infos = getMixerInfo();
      if (infos == null) {
        throw new IllegalArgumentException("No system default mixer installed"); // $NON-NLS-1$
      }
      inf = infos[0];
    } else {
      inf = info;
    }

    for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        return ((MixerProvider) (providers.next())).getMixer(inf);
      } catch (ClassCastException e) {
      } catch (IllegalArgumentException e) {
      }
    }
    throw new IllegalArgumentException("Mixer not supported: " + inf); // $NON-NLS-1$
  }