mirror of https://github.com/sipwise/jitsi.git
parent
490ac79046
commit
cca2bc13d0
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.audionotifier;
|
||||
|
||||
import net.java.sip.communicator.service.audionotifier.*;
|
||||
import net.java.sip.communicator.service.configuration.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The AudioNotifier activator class.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class AudioNotifierActivator implements BundleActivator
|
||||
{
|
||||
private AudioNotifierImpl audioNotifier;
|
||||
|
||||
private ConfigurationService configService;
|
||||
|
||||
private static Logger logger = Logger.getLogger(
|
||||
AudioNotifierActivator.class.getName());
|
||||
|
||||
/**
|
||||
* Called when this bundle is started.
|
||||
*
|
||||
* @param bundleContext The execution context of the bundle being started.
|
||||
*/
|
||||
public void start(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
try {
|
||||
//Create the audio notifier service
|
||||
audioNotifier = new AudioNotifierImpl();
|
||||
|
||||
ServiceReference configReference = bundleContext
|
||||
.getServiceReference(ConfigurationService.class.getName());
|
||||
|
||||
configService = (ConfigurationService) bundleContext
|
||||
.getService(configReference);
|
||||
|
||||
String isSoundEnabled = configService.getString(
|
||||
"net.java.sip.communicator.impl.sound.isSoundEnabled");
|
||||
|
||||
if(isSoundEnabled != null && isSoundEnabled != "") {
|
||||
audioNotifier.setMute(
|
||||
!new Boolean(isSoundEnabled).booleanValue());
|
||||
}
|
||||
|
||||
logger.logEntry();
|
||||
|
||||
logger.info("Audio Notifier Service...[ STARTED ]");
|
||||
|
||||
bundleContext.registerService(AudioNotifierService.class.getName(),
|
||||
audioNotifier, null);
|
||||
|
||||
logger.info("Audio Notifier Service ...[REGISTERED]");
|
||||
|
||||
} finally {
|
||||
logger.logExit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this bundle is stopped so the Framework can perform the
|
||||
* bundle-specific activities necessary to stop the bundle.
|
||||
*
|
||||
* @param bundleContext The execution context of the bundle being stopped.
|
||||
* @throws Exception If this method throws an exception, the bundle is
|
||||
* still marked as stopped, and the Framework will remove the bundle's
|
||||
* listeners, unregister all services registered by the bundle, and
|
||||
* release all services used by the bundle.
|
||||
*/
|
||||
public void stop(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
//TODO: Stop all currently playing sounds here
|
||||
try {
|
||||
configService.setProperty(
|
||||
"net.java.sip.communicator.impl.sound.isSoundEnabled",
|
||||
new Boolean(!audioNotifier.isMute()));
|
||||
|
||||
}
|
||||
catch (PropertyVetoException e1) {
|
||||
logger.error("The proposed property change "
|
||||
+ "represents an unacceptable value");
|
||||
}
|
||||
|
||||
logger.info("AudioNotifier Service ...[STOPPED]");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.audionotifier;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.audionotifier.*;
|
||||
|
||||
/**
|
||||
* The implementation of the AudioNotifierService.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class AudioNotifierImpl
|
||||
implements AudioNotifierService
|
||||
{
|
||||
|
||||
private static Map audioClips = new HashMap();
|
||||
|
||||
private boolean isMute;
|
||||
|
||||
/**
|
||||
* Creates an SCAudioClip from the given uri and adds it to the list of
|
||||
* available audios.
|
||||
*
|
||||
* @param uri the path where the audio file could be found
|
||||
*/
|
||||
public SCAudioClip createAudio(String uri)
|
||||
{
|
||||
SCAudioClip audioClip;
|
||||
|
||||
synchronized (audioClips)
|
||||
{
|
||||
if(audioClips.containsKey(uri))
|
||||
{
|
||||
audioClip = (SCAudioClip) audioClips.get(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
URL url = AudioNotifierImpl.class.getClassLoader()
|
||||
.getResource(uri);
|
||||
|
||||
audioClip = new SCAudioClipImpl(url);
|
||||
|
||||
audioClips.put(uri, audioClip);
|
||||
}
|
||||
}
|
||||
|
||||
return audioClip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given audio from the list of available audio clips.
|
||||
*
|
||||
* @param audioClip the audio to destroy
|
||||
*/
|
||||
public void destroyAudio(SCAudioClip audioClip)
|
||||
{
|
||||
synchronized (audioClips) {
|
||||
audioClips.remove(audioClip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the sound in the application. If FALSE, we try to
|
||||
* restore all looping sounds if any.
|
||||
*
|
||||
* @param isMute when TRUE disables the sound, otherwise enables the sound.
|
||||
*/
|
||||
public void setMute(boolean isMute)
|
||||
{
|
||||
this.isMute = isMute;
|
||||
|
||||
Iterator audios = audioClips.entrySet().iterator();
|
||||
|
||||
while (audios.hasNext())
|
||||
{
|
||||
SCAudioClipImpl audioClip
|
||||
= (SCAudioClipImpl) ((Map.Entry) audios.next()).getValue();
|
||||
|
||||
if (isMute)
|
||||
{
|
||||
audioClip.internalStop();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(audioClip.isLooping())
|
||||
{
|
||||
audioClip.playInLoop(audioClip.getLoopInterval());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the sound is currently disabled, FALSE otherwise.
|
||||
* @return TRUE if the sound is currently disabled, FALSE otherwise
|
||||
*/
|
||||
public boolean isMute()
|
||||
{
|
||||
return isMute;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.audionotifier;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.service.audionotifier.*;
|
||||
|
||||
/**
|
||||
* Implementation of SCAudioClip.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class SCAudioClipImpl implements SCAudioClip
|
||||
{
|
||||
private static Constructor acConstructor = null;
|
||||
|
||||
private Timer playAudioTimer = new Timer(1000, null);
|
||||
|
||||
private AudioClip audioClip;
|
||||
|
||||
private boolean isInvalid;
|
||||
|
||||
private boolean isLooping;
|
||||
|
||||
private int loopInterval;
|
||||
|
||||
private ActionListener audioListener;
|
||||
|
||||
/**
|
||||
* Creates the audio clip and initialize the listener used from the
|
||||
* loop timer.
|
||||
*
|
||||
* @param url the url pointing to the audio file
|
||||
*/
|
||||
public SCAudioClipImpl(URL url)
|
||||
{
|
||||
InputStream inputstream;
|
||||
try {
|
||||
inputstream = url.openStream();
|
||||
this.createAppletAudioClip(inputstream);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.audioListener = new PlayAudioListener(audioClip);
|
||||
this.playAudioTimer.addActionListener(audioListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays this audio.
|
||||
*/
|
||||
public void play()
|
||||
{
|
||||
if (audioClip != null)
|
||||
audioClip.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays this audio in loop.
|
||||
*
|
||||
* @param interval the loop interval
|
||||
*/
|
||||
public void playInLoop(int interval)
|
||||
{
|
||||
this.loopInterval = interval;
|
||||
|
||||
if(interval == 0)
|
||||
audioClip.loop();
|
||||
else
|
||||
{
|
||||
//first play the audio and then start the timer and wait
|
||||
audioClip.play();
|
||||
playAudioTimer.setDelay(interval);
|
||||
playAudioTimer.setRepeats(true);
|
||||
|
||||
playAudioTimer.start();
|
||||
}
|
||||
|
||||
this.isLooping = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops this audio.
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
if (audioClip != null)
|
||||
audioClip.stop();
|
||||
|
||||
if(isLooping)
|
||||
{
|
||||
playAudioTimer.stop();
|
||||
this.isLooping = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops this audio without setting the isLooping property in the case of
|
||||
* a looping audio. The AudioNotifier uses this method to stop the audio
|
||||
* when setMute(true) is invoked. This allows us to restore all looping
|
||||
* audios when the sound is restored by calling setMute(false).
|
||||
*/
|
||||
public void internalStop()
|
||||
{
|
||||
if (audioClip != null)
|
||||
audioClip.stop();
|
||||
|
||||
if(isLooping)
|
||||
{
|
||||
playAudioTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AppletAudioClip.
|
||||
*
|
||||
* @param inputstream the audio input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
private void createAppletAudioClip(InputStream inputstream)
|
||||
throws IOException
|
||||
{
|
||||
if(acConstructor == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
acConstructor = (Constructor)AccessController
|
||||
.doPrivileged(new PrivilegedExceptionAction()
|
||||
{
|
||||
public Object run()
|
||||
throws NoSuchMethodException,
|
||||
SecurityException,
|
||||
ClassNotFoundException
|
||||
{
|
||||
|
||||
Class class1 = null;
|
||||
try
|
||||
{
|
||||
class1 = Class.forName(
|
||||
"com.sun.media.sound.JavaSoundAudioClip",
|
||||
true, ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
catch(ClassNotFoundException classnotfoundexception)
|
||||
{
|
||||
class1 = Class.forName(
|
||||
"sun.audio.SunAudioClip", true, null);
|
||||
}
|
||||
Class aclass[] = new Class[1];
|
||||
aclass[0] = Class.forName("java.io.InputStream");
|
||||
return class1.getConstructor(aclass);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(PrivilegedActionException privilegedactionexception)
|
||||
{
|
||||
throw new IOException("Failed to get AudioClip constructor: "
|
||||
+ privilegedactionexception.getException());
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Object aobj[] = {
|
||||
inputstream
|
||||
};
|
||||
audioClip = (AudioClip)acConstructor.newInstance(aobj);
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
throw new IOException("Failed to construct the AudioClip: "
|
||||
+ exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays an audio clip. Used in the playAudioTimer to play an audio in loop.
|
||||
*/
|
||||
private static class PlayAudioListener implements ActionListener
|
||||
{
|
||||
private AudioClip audio;
|
||||
|
||||
public PlayAudioListener(AudioClip audio)
|
||||
{
|
||||
this.audio = audio;
|
||||
}
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
this.audio.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if this audio is invalid, FALSE otherwise.
|
||||
*
|
||||
* @return TRUE if this audio is invalid, FALSE otherwise
|
||||
*/
|
||||
public boolean isInvalid()
|
||||
{
|
||||
return isInvalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this audio as invalid or not.
|
||||
*
|
||||
* @param isInvalid TRUE to mark this audio as invalid, FALSE otherwise
|
||||
*/
|
||||
public void setInvalid(boolean isInvalid)
|
||||
{
|
||||
this.isInvalid = isInvalid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if this audio is currently playing in loop, FALSE otherwise.
|
||||
* @return TRUE if this audio is currently playing in loop, FALSE otherwise.
|
||||
*/
|
||||
public boolean isLooping()
|
||||
{
|
||||
return isLooping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loop interval if this audio is looping.
|
||||
* @return the loop interval if this audio is looping
|
||||
*/
|
||||
public int getLoopInterval()
|
||||
{
|
||||
return loopInterval;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
Bundle-Activator: net.java.sip.communicator.impl.audionotifier.AudioNotifierActivator
|
||||
Bundle-Name: Audio Notifier Service Provider Implementation
|
||||
Bundle-Description: An implementation of the AudioNotifier service.
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
Export-Package: net.java.sip.communicator.service.audionotifier
|
||||
Import-Package: org.osgi.framework,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.service.audionotifier,
|
||||
net.java.sip.communicator.service.configuration,
|
||||
javax.swing
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.audionotifier;
|
||||
|
||||
/**
|
||||
* The AudioNotifierService is meant to be used to control all sounds in the
|
||||
* application. An audio could be created by calling the createAudio method.
|
||||
* In order to stop all sounds in the application one could call the setMute
|
||||
* method. To check whether the sound is currently enabled the isMute method
|
||||
* could be used.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public interface AudioNotifierService
|
||||
{
|
||||
/**
|
||||
* Creates an SCAudioClip and returns it.
|
||||
* @param uri the uri, which will be the source of the audio
|
||||
* @return the created SCAudioClip, that could be played.
|
||||
*/
|
||||
public SCAudioClip createAudio(String uri);
|
||||
|
||||
/**
|
||||
* Destroys the given audio.
|
||||
*/
|
||||
public void destroyAudio(SCAudioClip audio);
|
||||
|
||||
/**
|
||||
* Stops/Restores all currently playing sounds.
|
||||
*/
|
||||
public void setMute(boolean isMute);
|
||||
|
||||
/**
|
||||
* Specifies if currently the sound is off.
|
||||
*
|
||||
* @return TRUE if currently the sound is off, FALSE otherwise
|
||||
*/
|
||||
public boolean isMute();
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.audionotifier;
|
||||
|
||||
/**
|
||||
* The SCAudioClip represents an audio clip created using the
|
||||
* AudioNotifierService. Like any audio it could be played, stopped or played in
|
||||
* loop.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public interface SCAudioClip
|
||||
{
|
||||
/**
|
||||
* Plays this audio.
|
||||
*/
|
||||
public void play();
|
||||
|
||||
/**
|
||||
* Plays this audio in loop.
|
||||
*
|
||||
*/
|
||||
public void playInLoop(int silenceInterval);
|
||||
|
||||
/**
|
||||
* Stops this audio.
|
||||
*/
|
||||
public void stop();
|
||||
}
|
||||
Loading…
Reference in new issue