Search in sources :

Example 1 with AudioSink

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

the class KodiHandlerFactory method createHandler.

@Override
@Nullable
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (thingTypeUID.equals(THING_TYPE_KODI)) {
        String callbackUrl = createCallbackUrl();
        KodiHandler handler = new KodiHandler(thing, commandDescriptionProvider, stateDescriptionProvider, webSocketClient, callbackUrl);
        // register the Kodi as an audio sink
        KodiAudioSink audioSink = new KodiAudioSink(handler, audioHTTPServer, callbackUrl);
        @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), audioSink, new Hashtable<>());
        audioSinkRegistrations.put(thing.getUID().toString(), reg);
        return handler;
    }
    return null;
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) KodiHandler(org.openhab.binding.kodi.internal.handler.KodiHandler) Hashtable(java.util.Hashtable) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ServiceRegistration(org.osgi.framework.ServiceRegistration) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with AudioSink

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

the class SonosHandlerFactory method createHandler.

@Override
@Nullable
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
        logger.debug("Creating a ZonePlayerHandler for thing '{}' with UDN '{}'", thing.getUID(), thing.getConfiguration().get(UDN));
        ZonePlayerHandler handler = new ZonePlayerHandler(thingRegistry, thing, upnpIOService, opmlUrl, stateDescriptionProvider);
        // register the speaker as an audio sink
        String callbackUrl = createCallbackUrl();
        SonosAudioSink audioSink = new SonosAudioSink(handler, audioHTTPServer, callbackUrl);
        @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) getBundleContext().registerService(AudioSink.class.getName(), audioSink, new Hashtable<>());
        audioSinkRegistrations.put(thing.getUID().toString(), reg);
        return handler;
    }
    return null;
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) ZonePlayerHandler(org.openhab.binding.sonos.internal.handler.ZonePlayerHandler) Hashtable(java.util.Hashtable) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ServiceRegistration(org.osgi.framework.ServiceRegistration) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with AudioSink

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

the class OnkyoHandlerFactory method createHandler.

@Override
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
        String callbackUrl = createCallbackUrl();
        OnkyoHandler handler = new OnkyoHandler(thing, upnpIOService, audioHTTPServer, callbackUrl, stateDescriptionProvider);
        if (callbackUrl != null) {
            @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), handler, new Hashtable<>());
            audioSinkRegistrations.put(thing.getUID().toString(), reg);
        }
        return handler;
    }
    return null;
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) Hashtable(java.util.Hashtable) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) OnkyoHandler(org.openhab.binding.onkyo.internal.handler.OnkyoHandler) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 4 with AudioSink

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

the class PulseaudioHandler method audioSinkSetup.

private void audioSinkSetup() {
    final PulseaudioHandler thisHandler = this;
    scheduler.submit(new Runnable() {

        @Override
        public void run() {
            // Register the sink as an audio sink in openhab
            logger.trace("Registering an audio sink for pulse audio sink thing {}", thing.getUID());
            PulseAudioAudioSink audioSink = new PulseAudioAudioSink(thisHandler, scheduler);
            setAudioSink(audioSink);
            try {
                audioSink.connectIfNeeded();
            } catch (IOException e) {
                logger.warn("pulseaudio binding cannot connect to the module-simple-protocol-tcp on {} ({})", getHost(), e.getMessage());
            } catch (InterruptedException i) {
                logger.info("Interrupted during sink audio connection: {}", i.getMessage());
                return;
            } finally {
                audioSink.scheduleDisconnect();
            }
            @SuppressWarnings("unchecked") ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext.registerService(AudioSink.class.getName(), audioSink, new Hashtable<>());
            audioSinkRegistrations.put(thing.getUID().toString(), reg);
        }
    });
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) PulseAudioAudioSink(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink) IOException(java.io.IOException) PulseAudioAudioSink(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 5 with AudioSink

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

the class PulseaudioHandler method dispose.

@Override
public void dispose() {
    ScheduledFuture<?> job = refreshJob;
    if (job != null && !job.isCancelled()) {
        job.cancel(true);
        refreshJob = null;
    }
    PulseaudioBridgeHandler briHandler = bridgeHandler;
    if (briHandler != null) {
        briHandler.unregisterDeviceStatusListener(this);
        bridgeHandler = null;
    }
    logger.trace("Thing {} {} disposed.", getThing().getUID(), name);
    super.dispose();
    PulseAudioAudioSink sink = audioSink;
    if (sink != null) {
        sink.disconnect();
    }
    PulseAudioAudioSource source = audioSource;
    if (source != null) {
        source.disconnect();
    }
    // Unregister the potential pulse audio sink's audio sink
    ServiceRegistration<AudioSink> sinkReg = audioSinkRegistrations.remove(getThing().getUID().toString());
    if (sinkReg != null) {
        logger.trace("Unregistering the audio sync service for pulse audio sink thing {}", getThing().getUID());
        sinkReg.unregister();
    }
    // Unregister the potential pulse audio source's audio sources
    ServiceRegistration<AudioSource> sourceReg = audioSourceRegistrations.remove(getThing().getUID().toString());
    if (sourceReg != null) {
        logger.trace("Unregistering the audio sync service for pulse audio source thing {}", getThing().getUID());
        sourceReg.unregister();
    }
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) PulseAudioAudioSink(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink) AudioSource(org.openhab.core.audio.AudioSource) PulseAudioAudioSource(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSource) PulseAudioAudioSink(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink) PulseAudioAudioSource(org.openhab.binding.pulseaudio.internal.PulseAudioAudioSource)

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