Search in sources :

Example 1 with AnnotationLocalServiceBinder

use of org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder in project BeyondUPnP by kevinshine.

the class BeyondUpnpService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    //Create LocalDevice
    LocalService localService = new AnnotationLocalServiceBinder().read(BeyondContentDirectoryService.class);
    localService.setManager(new DefaultServiceManager<>(localService, BeyondContentDirectoryService.class));
    String macAddress = Utils.getMACAddress(Utils.WLAN0);
    //Generate UUID by MAC address
    UDN udn = UDN.valueOf(UUID.nameUUIDFromBytes(macAddress.getBytes()).toString());
    try {
        mLocalDevice = new LocalDevice(new DeviceIdentity(udn), new UDADeviceType("MediaServer"), new DeviceDetails("Local Media Server"), new LocalService[] { localService });
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    upnpService.getRegistry().addDevice(mLocalDevice);
    //LocalBinder instead of binder
    binder = new LocalBinder();
}
Also used : BeyondContentDirectoryService(com.kevinshen.beyondupnp.core.upnp.BeyondContentDirectoryService) DeviceIdentity(org.fourthline.cling.model.meta.DeviceIdentity) DeviceDetails(org.fourthline.cling.model.meta.DeviceDetails) ValidationException(org.fourthline.cling.model.ValidationException) LocalDevice(org.fourthline.cling.model.meta.LocalDevice) UDADeviceType(org.fourthline.cling.model.types.UDADeviceType) LocalService(org.fourthline.cling.model.meta.LocalService) AnnotationLocalServiceBinder(org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder) UDN(org.fourthline.cling.model.types.UDN)

Example 2 with AnnotationLocalServiceBinder

use of org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder in project libresonic by Libresonic.

the class UPnPService method createMediaServerDevice.

private LocalDevice createMediaServerDevice() throws Exception {
    String serverName = settingsService.getDlnaServerName();
    DeviceIdentity identity = new DeviceIdentity(UDN.uniqueSystemIdentifier(serverName));
    DeviceType type = new UDADeviceType("MediaServer", 1);
    // TODO: DLNACaps
    DeviceDetails details = new DeviceDetails(serverName, new ManufacturerDetails(serverName), new ModelDetails(serverName), new DLNADoc[] { new DLNADoc("DMS", DLNADoc.Version.V1_5) }, null);
    Icon icon = new Icon("image/png", 512, 512, 32, "logo-512", getClass().getResourceAsStream("logo-512.png"));
    LocalService<FolderBasedContentDirectory> contentDirectoryservice = new AnnotationLocalServiceBinder().read(FolderBasedContentDirectory.class);
    contentDirectoryservice.setManager(new DefaultServiceManager<FolderBasedContentDirectory>(contentDirectoryservice) {

        @Override
        protected FolderBasedContentDirectory createServiceInstance() throws Exception {
            return folderBasedContentDirectory;
        }
    });
    final ProtocolInfos protocols = new ProtocolInfos();
    for (DLNAProfiles dlnaProfile : DLNAProfiles.values()) {
        if (dlnaProfile == DLNAProfiles.NONE) {
            continue;
        }
        try {
            protocols.add(new DLNAProtocolInfo(dlnaProfile));
        } catch (Exception e) {
        // Silently ignored.
        }
    }
    LocalService<ConnectionManagerService> connetionManagerService = new AnnotationLocalServiceBinder().read(ConnectionManagerService.class);
    connetionManagerService.setManager(new DefaultServiceManager<ConnectionManagerService>(connetionManagerService) {

        @Override
        protected ConnectionManagerService createServiceInstance() throws Exception {
            return new ConnectionManagerService(protocols, null);
        }
    });
    // For compatibility with Microsoft
    LocalService<MSMediaReceiverRegistrarService> receiverService = new AnnotationLocalServiceBinder().read(MSMediaReceiverRegistrarService.class);
    receiverService.setManager(new DefaultServiceManager<>(receiverService, MSMediaReceiverRegistrarService.class));
    return new LocalDevice(identity, type, details, new Icon[] { icon }, new LocalService[] { contentDirectoryservice, connetionManagerService, receiverService });
}
Also used : UDADeviceType(org.fourthline.cling.model.types.UDADeviceType) DLNAProtocolInfo(org.fourthline.cling.support.model.dlna.DLNAProtocolInfo) AnnotationLocalServiceBinder(org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder) ConnectionManagerService(org.fourthline.cling.support.connectionmanager.ConnectionManagerService) UDADeviceType(org.fourthline.cling.model.types.UDADeviceType) DeviceType(org.fourthline.cling.model.types.DeviceType) DLNAProfiles(org.fourthline.cling.support.model.dlna.DLNAProfiles) MSMediaReceiverRegistrarService(org.libresonic.player.service.upnp.MSMediaReceiverRegistrarService) ProtocolInfos(org.fourthline.cling.support.model.ProtocolInfos) DLNADoc(org.fourthline.cling.model.types.DLNADoc) FolderBasedContentDirectory(org.libresonic.player.service.upnp.FolderBasedContentDirectory)

Aggregations

AnnotationLocalServiceBinder (org.fourthline.cling.binding.annotations.AnnotationLocalServiceBinder)2 UDADeviceType (org.fourthline.cling.model.types.UDADeviceType)2 BeyondContentDirectoryService (com.kevinshen.beyondupnp.core.upnp.BeyondContentDirectoryService)1 ValidationException (org.fourthline.cling.model.ValidationException)1 DeviceDetails (org.fourthline.cling.model.meta.DeviceDetails)1 DeviceIdentity (org.fourthline.cling.model.meta.DeviceIdentity)1 LocalDevice (org.fourthline.cling.model.meta.LocalDevice)1 LocalService (org.fourthline.cling.model.meta.LocalService)1 DLNADoc (org.fourthline.cling.model.types.DLNADoc)1 DeviceType (org.fourthline.cling.model.types.DeviceType)1 UDN (org.fourthline.cling.model.types.UDN)1 ConnectionManagerService (org.fourthline.cling.support.connectionmanager.ConnectionManagerService)1 ProtocolInfos (org.fourthline.cling.support.model.ProtocolInfos)1 DLNAProfiles (org.fourthline.cling.support.model.dlna.DLNAProfiles)1 DLNAProtocolInfo (org.fourthline.cling.support.model.dlna.DLNAProtocolInfo)1 FolderBasedContentDirectory (org.libresonic.player.service.upnp.FolderBasedContentDirectory)1 MSMediaReceiverRegistrarService (org.libresonic.player.service.upnp.MSMediaReceiverRegistrarService)1