📄 icemailmedia.java
字号:
/*** $Id: ICEMailMedia.java,v 1.3 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import java.io.InputStream;import java.io.IOException;import sun.audio.AudioPlayer;import sun.audio.AudioStream;import org.icemail.util.UserProperties;import org.icemail.util.ResourceUtilities;/** * This class manages the media resources, i.e. sound, etc. * The class presents a static interface for setting and using the each resource. */public class ICEMailMedia{ static public final String SunAudioAPIName = "SunAudio"; static public final String JmfAudioAPIName = "JMFAudio"; static private boolean incomingSoundFlag = false; static private String incomingSoundURL = null; /** * Default constructor. * Private to eliminate instantiations. */ private ICEMailMedia() { } /** * Set the incoming sound controls. * * @param flag true if the sound should be played * @param url URL of the sound resource */ static public void setIncomingSound( boolean flag, String url ) { ICEMailMedia.incomingSoundFlag = flag; ICEMailMedia.incomingSoundURL = url; Configuration xconfig = Configuration.getInstance(); xconfig.setProperty( Configuration.P_INCOMING_SOUND_FLAG, flag ); if ( url != null && url.length() > 0 ) { xconfig.setProperty( Configuration.P_INCOMING_SOUND_URL, url ); } else { xconfig.removeProperty( Configuration.P_INCOMING_SOUND_URL ); ICEMailMedia.incomingSoundURL = null; } xconfig.saveProperties(); } /** * Play the incoming sound. */ static public void playIncomingSound() { if ( ICEMailMedia.incomingSoundURL == null ) { initializeResources(); } if ( ICEMailMedia.incomingSoundFlag ) { playAudioClip( ICEMailMedia.SunAudioAPIName, ICEMailMedia.incomingSoundURL ); } } /** * Load an audio clip by the given path. * * @param apiName audio api to use for obtaining resource * @param audioPath URL of the audio resource * @see ICEMailMedia.SunAudioAPIName */ static public void loadAudioClip( String apiName, String audioPath ) { if ( apiName.equalsIgnoreCase( ICEMailMedia.SunAudioAPIName ) ) { loadSunAudioClip( audioPath ); } else { System.err.println( "ERROR loading, unknown audio API '" + apiName + "'" ); } } /** * Play an audio clip by the given path. * * @param apiName audio api to use for obtaining resource * @param audioPath URL of the audio resource * @see ICEMailMedia.SunAudioAPIName */ static public void playAudioClip( String apiName, String audioPath ) { if ( apiName.equalsIgnoreCase( ICEMailMedia.SunAudioAPIName ) ) { playSunAudioClip( audioPath ); } else { System.err.println( "ERROR playing, unknown audio API '" + apiName + "'" ); } }//............................................................ static private void initializeResources() { ICEMailMedia.incomingSoundFlag = UserProperties.getProperty( Configuration.P_INCOMING_SOUND_FLAG, false ); ICEMailMedia.incomingSoundURL = UserProperties.getProperty( Configuration.P_INCOMING_SOUND_URL, null ); } static private void loadSunAudioClip( String audioPath ) { // This is currently noop-ed. What is intended is to deal // with extreme loading cases (sound out on the web for instance) // and make sure it is more readily avilable at play time. } static private void playSunAudioClip( String audioPath ) { InputStream in = null; try { in = ResourceUtilities.openNamedResource( audioPath ); if ( in != null ) { AudioStream audioClip = new AudioStream( in ); AudioPlayer.player.start( audioClip ); } } catch ( IOException ex ) { ex.printStackTrace( System.err ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -