MixerUtil.java 文件源码

java
阅读 21 收藏 0 点赞 0 评论 0

项目:crowdpp 作者:
/**
 * Find a mixer that matches a given name.
 * 
 * @param mixerName as returned by a previous call of Mixer.Info.getName()
 * @param forRecording whether looking for a recording device (or playback otherwise). This 
 * information is needed because otherwise, mixer names are ambiguous. 
 * @return the matching Mixer.Info from AudioSystem.getMixerInfo() or null when there's no match
 * @throws Exception for multiple matches
 */
public static Mixer.Info getMixerInfoFromName(String mixerName, boolean forRecording) throws Exception{
    if (mixerName == null)
        return AudioSystem.getMixer(null).getMixerInfo();

    Mixer.Info [] availableMixers = AudioSystem.getMixerInfo();

    Mixer.Info info = null;

    for (Mixer.Info m : availableMixers){
        // don't consider playing mixers - otherwise, the mixer names are ambiguous
        if (!AudioSystem.getMixer(m).isLineSupported(
                forRecording ? 
                        new Info(TargetDataLine.class) :
                            new Info(SourceDataLine.class))){
            //System.out.println(mixerName + ": Not considering");

            continue;
        }
        if (m.getName().trim().equals(mixerName)){
            if (info != null){
                throw new Exception(String.format("multiple matches for \"%s\": \"%s\" and \"%s\"",
                        mixerName, info, m.getName()));
            }
            info = m;
        }
    }
    return info;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号