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;
}
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;
}
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;
}
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);
}
});
}
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();
}
}
Aggregations