/* * [Audio.java] * * Summary: Makes sounds, mostly verbal error messages. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 3.8 2009-03-31 change order of fields in defaults.csv. */ package com.mindprod.vercheck; import com.mindprod.common18.Play; import javax.sound.sampled.UnsupportedAudioFileException; import java.io.IOException; import java.net.URL; import static java.lang.System.*; /** * Makes sounds, mostly verbal error messages. * * @author Roedy Green, Canadian Mind Products * @version 3.8 2009-03-31 change order of fields in defaults.csv. * @since 2009 */ public enum Audio { // usually Sun signed 8-bit PCM au 48,000 Hz 384 kbps mono BAD_DATE( "baddate.au" ), BAD_URL( "badurl.au" ), CLICK( "click.au" ), DONE( "done.au" ), FUTURE_DATE( "futuredate.au" ), INCOMPLETE( "incomplete.au" ), INVALID_REGEX( "invalidregex.au" ), NEW_VERSION( "newversion.au" ), UNABLE_TO_CONNECT( "unabletoconnect.au" ); private static final String WHY_SOUND_FAILS = " or possible missing or malfunctioning sound card, " + "or dirty contacts on your speaker cable."; /** * name of this sound file in the jar */ private final String resource; /** * constructor * * @param resource name of resource sound file */ Audio( String resource ) { this.resource = resource; } /** * play sound matching this enum */ public void play() { try { URL url = Audio.class.getResource( "sound/" + resource ); if ( url == null ) { err.println( "Can't find sound resource " + resource ); return; } Play.play( url ); } catch ( UnsupportedAudioFileException e ) { err.println( "Unsupported Audio file format for " + resource + WHY_SOUND_FAILS ); } catch ( IOException e ) { err.println( "Problems fetching sound data for " + resource + WHY_SOUND_FAILS ); } catch ( Exception e ) { err.println( "Problem playing sound for " + resource + WHY_SOUND_FAILS ); e.printStackTrace( err ); } } }