Connect SDK:共享本地图像

问题描述 投票:0回答:1

我使用Connect-SDK-Android-API-Sampler,并使用mediaURL“ www.example.com/image.jpg”将图像共享到电视中。

如何共享设备中的本地图像?

android share live-connect-sdk
1个回答
0
投票

我的问题的解决方案是Web服务器。我使用了NanoHTTPD库。

public class WebServer extends NanoHTTPD {

    private int port;

    public WebServer(int port) {
        super(port);
        this.port = port;
    }

    @Override
    public Response serve(IHTTPSession session) {
        Method method = session.getMethod();
        switch (method) {
            case GET:
                String path = session.getUri().replace(Utils.getIPAddress(true) + ":" + port, "");

                //TODO refactoring
                String type = FilenameUtils.getExtension(path);
                String filePath = Environment.getExternalStorageDirectory() + path;
                String contentType = "";
                if (type.equals("jpg") || type.equals("jpeg") || type.equals("png") || type.equals("gif") || type.equals("tiff"))
                    contentType = "image/" + type;
                else
                    return new Response(Response.Status.BAD_REQUEST, NanoHTTPD.MIME_PLAINTEXT, "HTTPError: HTTP 8: BAD REQUEST");

                if (fileInputStream != null)
                    fileInputStream.close();
                try {
                    fileInputStream = new FileInputStream(filePath);
                } catch (FileNotFoundException e) {
                    new Response(Response.Status.BAD_REQUEST, NanoHTTPD.MIME_PLAINTEXT, "HTTPError: HTTP 8: BAD REQUEST");
                }
                return new Response(Response.Status.OK, contentType, fileInputStream);

            default:
                return new Response(Response.Status.METHOD_NOT_ALLOWED, NanoHTTPD.MIME_PLAINTEXT, "HTTPError: HTTP 405: Method Not Allowed");
        }
    }
}

0
投票

我正在将此sd​​k用于遥控器。我需要在电视上显示我的iPhone移动本地图像,该怎么办?我已经在SDK中看到,需要提供实时服务器网址才能在电视上显示它。就我而言,我需要在电视上显示我的本地画廊图像。我无法理解我需要遵循哪些步骤,请帮助我继续进行iOS。

© www.soinside.com 2019 - 2024. All rights reserved.