Search in sources :

Example 11 with AudioSink

use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.

the class SqueezeBoxHandlerFactory method removeHandler.

@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
    if (thingHandler instanceof SqueezeBoxServerHandler) {
        logger.trace("removing handler for bridge thing {}", thingHandler.getThing());
        ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
        if (serviceReg != null) {
            logger.trace("unregistering player discovery service");
            // Get the discovery service object and use it to cancel the RequestPlayerJob
            SqueezeBoxPlayerDiscoveryParticipant discoveryService = (SqueezeBoxPlayerDiscoveryParticipant) bundleContext.getService(serviceReg.getReference());
            discoveryService.cancelRequestPlayerJob();
            // Unregister the PlayerListener from the SqueezeBoxServerHandler
            ((SqueezeBoxServerHandler) thingHandler).unregisterSqueezeBoxPlayerListener((SqueezeBoxPlayerEventListener) bundleContext.getService(serviceReg.getReference()));
            // Unregister the PlayerListener service
            serviceReg.unregister();
            // Remove the service from the ServiceRegistration map
            discoveryServiceRegs.remove(thingHandler.getThing().getUID());
        }
    }
    if (thingHandler instanceof SqueezeBoxPlayerHandler) {
        SqueezeBoxServerHandler bridge = ((SqueezeBoxPlayerHandler) thingHandler).getSqueezeBoxServerHandler();
        if (bridge != null) {
            // Unregister the player's audio sink
            logger.trace("Unregistering the audio sync service for player thing {}", thingHandler.getThing().getUID());
            ServiceRegistration<AudioSink> reg = audioSinkRegistrations.get(thingHandler.getThing().getUID().toString());
            if (reg != null) {
                reg.unregister();
            }
            logger.trace("removing handler for player thing {}", thingHandler.getThing());
            bridge.removePlayerCache(((SqueezeBoxPlayerHandler) thingHandler).getMac());
        }
    }
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) SqueezeBoxPlayerHandler(org.openhab.binding.squeezebox.internal.handler.SqueezeBoxPlayerHandler) SqueezeBoxPlayerDiscoveryParticipant(org.openhab.binding.squeezebox.internal.discovery.SqueezeBoxPlayerDiscoveryParticipant) SqueezeBoxServerHandler(org.openhab.binding.squeezebox.internal.handler.SqueezeBoxServerHandler)

Example 12 with AudioSink

use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.

the class SqueezeBoxHandlerFactory method createHandler.

@Override
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (thingTypeUID.equals(SQUEEZEBOXSERVER_THING_TYPE)) {
        logger.trace("creating handler for bridge thing {}", thing);
        SqueezeBoxServerHandler bridge = new SqueezeBoxServerHandler((Bridge) thing);
        registerSqueezeBoxPlayerDiscoveryService(bridge);
        return bridge;
    }
    if (thingTypeUID.equals(SQUEEZEBOXPLAYER_THING_TYPE)) {
        logger.trace("creating handler for player thing {}", thing);
        SqueezeBoxPlayerHandler playerHandler = new SqueezeBoxPlayerHandler(thing, createCallbackUrl(), stateDescriptionProvider);
        // Register the player as an audio sink
        logger.trace("Registering an audio sink for player thing {}", thing.getUID());
        SqueezeBoxAudioSink audioSink = new SqueezeBoxAudioSink(playerHandler, audioHTTPServer, callbackUrl);
        @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), audioSink, new Hashtable<>());
        audioSinkRegistrations.put(thing.getUID().toString(), reg);
        return playerHandler;
    }
    return null;
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) SqueezeBoxPlayerHandler(org.openhab.binding.squeezebox.internal.handler.SqueezeBoxPlayerHandler) Hashtable(java.util.Hashtable) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) SqueezeBoxServerHandler(org.openhab.binding.squeezebox.internal.handler.SqueezeBoxServerHandler) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 13 with AudioSink

use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.

the class UpnpControlHandlerFactory method registerAudioSink.

@Override
public void registerAudioSink(UpnpRendererHandler handler) {
    if (!(callbackUrl.isEmpty())) {
        UpnpAudioSink audioSink = new UpnpAudioSink(handler, audioHTTPServer, callbackUrl);
        @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), audioSink, new Hashtable<String, Object>());
        Thing thing = handler.getThing();
        audioSinkRegistrations.put(thing.getUID().toString(), reg);
        logger.debug("Audio sink added for media renderer {}", thing.getLabel());
        UpnpNotificationAudioSink notificationAudioSink = new UpnpNotificationAudioSink(handler, audioHTTPServer, callbackUrl);
        @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> notificationReg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), notificationAudioSink, new Hashtable<String, Object>());
        audioSinkRegistrations.put(thing.getUID().toString() + NOTIFICATION_AUDIOSINK_EXTENSION, notificationReg);
        logger.debug("Notification audio sink added for media renderer {}", thing.getLabel());
    }
}
Also used : UpnpNotificationAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpNotificationAudioSink) AudioSink(org.openhab.core.audio.AudioSink) UpnpAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpAudioSink) UpnpAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpAudioSink) Hashtable(java.util.Hashtable) UpnpNotificationAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpNotificationAudioSink) Thing(org.openhab.core.thing.Thing) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 14 with AudioSink

use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.

the class HeosHandlerFactory method registerAudioSink.

private void registerAudioSink(Thing thing, HeosThingBaseHandler thingBaseHandler) {
    HeosAudioSink audioSink = new HeosAudioSink(thingBaseHandler, audioHTTPServer, createCallbackUrl());
    @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), audioSink, new Hashtable<>());
    audioSinkRegistrations.put(thing.getUID().toString(), reg);
}
Also used : HeosAudioSink(org.openhab.binding.heos.internal.api.HeosAudioSink) AudioSink(org.openhab.core.audio.AudioSink) Hashtable(java.util.Hashtable) HeosAudioSink(org.openhab.binding.heos.internal.api.HeosAudioSink) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 15 with AudioSink

use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.

the class ChromecastHandlerFactory method createHandler.

@Override
@Nullable
protected ThingHandler createHandler(Thing thing) {
    ChromecastHandler handler = new ChromecastHandler(thing, audioHTTPServer, createCallbackUrl());
    @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), handler, null);
    audioSinkRegistrations.put(thing.getUID().toString(), reg);
    return handler;
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) ChromecastHandler(org.openhab.binding.chromecast.internal.handler.ChromecastHandler) ServiceRegistration(org.osgi.framework.ServiceRegistration) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

AudioSink (org.openhab.core.audio.AudioSink)19 Locale (java.util.Locale)8 ServiceRegistration (org.osgi.framework.ServiceRegistration)8 Hashtable (java.util.Hashtable)6 AudioSource (org.openhab.core.audio.AudioSource)6 KSService (org.openhab.core.voice.KSService)5 STTService (org.openhab.core.voice.STTService)5 TTSService (org.openhab.core.voice.TTSService)5 HumanLanguageInterpreter (org.openhab.core.voice.text.HumanLanguageInterpreter)5 Nullable (org.eclipse.jdt.annotation.Nullable)4 Operation (io.swagger.v3.oas.annotations.Operation)3 Path (javax.ws.rs.Path)3 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 PulseAudioAudioSink (org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink)2 SqueezeBoxPlayerHandler (org.openhab.binding.squeezebox.internal.handler.SqueezeBoxPlayerHandler)2 SqueezeBoxServerHandler (org.openhab.binding.squeezebox.internal.handler.SqueezeBoxServerHandler)2