home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code


package com.ice.syslogd;

import java.net.*;
import java.util.*;
import java.applet.*;

import  sun.audio.*;    //import the sun.audio package
import  java.io.*;



/*
 * This class will need to be changed for every new
 * environment that the syslogd package is used in.
 * Specifically, the audio currently depends on an
 * available Applet, which is provided by the SyslogD
 * application in this instance.
 */

public class
SyslogMedia
	{
	public static final String		RCS_ID = "$Id: SyslogMedia.java,v 1.1.1.1 1998/02/22 05:47:54 time Exp $";
	public static final String		RCS_REV = "$Revision: 1.1.1.1 $";
	public static final String		RCS_NAME = "$Name:  $";

	static public final String		sunAudioAPIName = "SunAudio";
	static public final String		jmfAudioAPIName = "JMFAudio";

	static private Hashtable		audioCache;

	static
		{
		SyslogMedia.audioCache = new Hashtable();
		}

	static public void
	loadAudioClip( String apiName, String audioPath )
		{
		if ( apiName.equalsIgnoreCase( SyslogMedia.sunAudioAPIName ) )
			{
			SyslogMedia.loadSunAudioClip( audioPath );
			}
		else
			{
			System.err.println
				( "ERROR loading, unknown audio API '" + apiName + "'" );
			}
		}

	static public void
	playAudioClip( String apiName, String audioPath )
		{
		if ( apiName.equalsIgnoreCase( SyslogMedia.sunAudioAPIName ) )
			{
			SyslogMedia.playSunAudioClip( audioPath );
			}
		else
			{
			System.err.println
				( "ERROR playing, unknown audio API '" + apiName + "'" );
			}
		}

	static public void
	loadSunAudioClip( String audioPath )
		{
		//** add this into your application code as appropriate
		File audioFile = new File( audioPath );
		if ( ! audioFile.exists() )
			{
			System.err.println
				( "ERROR could not load audio clip '"
					+ audioPath + "', it does not exist." );
			}
		else
			{
			SyslogMedia.audioCache.put( audioPath, audioFile );
			}
		}

	static public void
	playSunAudioClip( String audioPath )
		{
		File audioFile = (File)
			SyslogMedia.audioCache.get( audioPath );

		if ( audioFile != null )
			{
			InputStream in = null;
			AudioStream audioClip = null;
			
			try {
				in = new FileInputStream( audioFile );
				audioClip = new AudioStream( in );
				AudioPlayer.player.start( audioClip );            
				}
			catch ( IOException ex )
				{
				System.err.println
					( "ERROR playing audioClip '" + audioPath
						+ "':\n\t" + ex.getMessage() );
				}
			}
		}

	}

new blog posts

 

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.