org.fourthline.cling.binding.LocalServiceBinder Java Examples

The following examples show how to use org.fourthline.cling.binding.LocalServiceBinder. 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 File: MediaServer.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
public MediaServer(final Context context) throws ValidationException, UnknownHostException {

        localAddress = getWIFIIpAddress(context);

        generateContentTask = new GenerateContentTask();
        generateContentTask.execute(context);

        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
                = binder.read(ContentDirectoryService.class);
        ServiceManager<ContentDirectoryService> contentDirectoryManger
                = new DefaultServiceManager<ContentDirectoryService>(contentDirectoryService) {
            @Override
            protected ContentDirectoryService createServiceInstance() throws Exception {
                return new ContentDirectoryService();
            }
        };
        contentDirectoryService.setManager(contentDirectoryManger);

        // 连接管理服务
        LocalService<ConnectionManagerService> connectionManagerService
                = binder.read(ConnectionManagerService.class);
        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);
            nanoHttpServer.start();
            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();
            e.printStackTrace();
        }

    }