1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.media.audiotestharness.utilities; 18 19 import java.util.Arrays; 20 import java.util.logging.Logger; 21 22 import javax.sound.sampled.AudioSystem; 23 import javax.sound.sampled.Mixer; 24 25 /** 26 * Helper binary that runs a diagnostic with the AudioSystem class to see if audio devices can be 27 * seen. This class can also be used to determine the name that the Java Audio System has assigned 28 * to the various devices connected to the system. 29 */ 30 public class AudioSystemDiagnostic { 31 public static final Logger LOGGER = Logger.getLogger(AudioSystemDiagnostic.class.getName()); 32 main(String args[])33 public static void main(String args[]) { 34 LOGGER.info("Audio System Diagnostic follows:\n" + buildAudioSystemDiagnosticString()); 35 } 36 37 /** 38 * Builds a string containing diagnostic information about the Java Sound API and the devices it 39 * can recognize. 40 */ buildAudioSystemDiagnosticString()41 public static String buildAudioSystemDiagnosticString() { 42 StringBuilder diagnosticStringBuilder = new StringBuilder(); 43 44 diagnosticStringBuilder.append("===== Java Audio System Diagnostic =====\n\n"); 45 46 diagnosticStringBuilder.append("----- Java Version Information -----\n"); 47 diagnosticStringBuilder.append( 48 "Java Version = " + System.getProperty("java.runtime.version") + "\n\n"); 49 50 diagnosticStringBuilder.append("----- Java Audio System Output -----\n"); 51 52 Mixer.Info[] mixers = AudioSystem.getMixerInfo(); 53 54 diagnosticStringBuilder.append("Mixers Array = " + Arrays.toString(mixers) + "\n"); 55 diagnosticStringBuilder.append("Number of Mixers = " + mixers.length + "\n"); 56 57 for (int i = 0; i < mixers.length; i++) { 58 Mixer.Info currentMixer = mixers[i]; 59 diagnosticStringBuilder.append("\n"); 60 diagnosticStringBuilder.append( 61 "----- Start Mixer (#" + Integer.toString(i) + ") -----\n"); 62 diagnosticStringBuilder.append("Mixer Name = " + currentMixer.getName() + "\n"); 63 diagnosticStringBuilder.append("Mixer Vendor = " + currentMixer.getVendor() + "\n"); 64 diagnosticStringBuilder.append("Mixer Version = " + currentMixer.getVersion() + "\n"); 65 diagnosticStringBuilder.append( 66 "Mixer Description = " + currentMixer.getDescription() + "\n"); 67 diagnosticStringBuilder.append( 68 "----- End Mixer (#" + Integer.toString(i) + ") -----\n"); 69 } 70 71 return diagnosticStringBuilder.toString(); 72 } 73 } 74