2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.upnpcontrol.internal.audiosink;
15 import static org.openhab.binding.upnpcontrol.internal.UpnpControlBindingConstants.NOTIFICATION_AUDIOSINK_EXTENSION;
17 import java.io.IOException;
18 import java.util.Locale;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.upnpcontrol.internal.handler.UpnpRendererHandler;
23 import org.openhab.core.audio.AudioHTTPServer;
24 import org.openhab.core.library.types.PercentType;
28 * This class works as a standard audio sink for openHAB, but with specific behavior for the audio players. It is only
29 * meant to be used for playing notifications. When sending audio through this sink, the previously playing media will
30 * be interrupted and will automatically resume after playing the notification. If no volume is specified, the
31 * notification volume will be controlled by the media player notification volume configuration.
33 * @author Mark Herwege - Initial contribution
36 public class UpnpNotificationAudioSink extends UpnpAudioSink {
38 public UpnpNotificationAudioSink(UpnpRendererHandler handler, AudioHTTPServer audioHTTPServer, String callbackUrl) {
39 super(handler, audioHTTPServer, callbackUrl);
43 public String getId() {
44 return handler.getThing().getUID().toString() + NOTIFICATION_AUDIOSINK_EXTENSION;
48 public @Nullable String getLabel(@Nullable Locale locale) {
49 return handler.getThing().getLabel() + NOTIFICATION_AUDIOSINK_EXTENSION;
53 public void setVolume(@Nullable PercentType volume) throws IOException {
55 handler.setNotificationVolume(volume);
60 protected void playMedia(String url) {
62 if (!url.startsWith("x-") && !url.startsWith("http")) {
63 newUrl = "x-file-cifs:" + url;
65 handler.playNotification(newUrl);