Java Code Examples for org.fourthline.cling.binding.LocalServiceBinder

The following examples show how to use org.fourthline.cling.binding.LocalServiceBinder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: HPlayer   Source File:    License: Apache License 2.0 4 votes vote down vote up
public MediaServer(final Context context) throws ValidationException, UnknownHostException {

        localAddress = getWIFIIpAddress(context);

        generateContentTask = new GenerateContentTask();

        udn = new UDN(UUID.randomUUID());
        DeviceType type = new UDADeviceType(deviceType, version);

        DeviceDetails details = new DeviceDetails(android.os.Build.MODEL,
                new ManufacturerDetails(android.os.Build.MANUFACTURER),
                new ModelDetails("HPlayer", "HPlayer MediaServer for Android", "v1"));

        LocalServiceBinder binder = new AnnotationLocalServiceBinder();

        // 文件共享服务
        LocalService<ContentDirectoryService> contentDirectoryService
        ServiceManager<ContentDirectoryService> contentDirectoryManger
                = new DefaultServiceManager<ContentDirectoryService>(contentDirectoryService) {
            protected ContentDirectoryService createServiceInstance() throws Exception {
                return new ContentDirectoryService();

        // 连接管理服务
        LocalService<ConnectionManagerService> connectionManagerService
        connectionManagerService.setManager(new DefaultServiceManager<>(
                connectionManagerService, ConnectionManagerService.class));

        // TODO 添加 AVTransportService
        // TODO 添加 AudioRenderingControl

        localDevice = new LocalDevice(new DeviceIdentity(udn), type, details,
                new LocalService[]{contentDirectoryService, connectionManagerService});

        // 启动服务器
        try {
            nanoHttpServer = new NanoHttpServer(port);
            Log.d(TAG, "Started Http Server on port " + port);
        } catch (IOException e) {
            Log.d(TAG, "Started Http Server on error:" + e.getMessage());
            Toast.makeText(context, "启动服务器失败!", Toast.LENGTH_SHORT).show();