React-Native无法正确使用jni库

时间:2018-05-16 17:38:00

标签: react-native java-native-interface nanohttpd

我在我的原生java代码中使用nanohttpd。当我使用它时,一切看起来都不错,但是当我使用jni库方法时,它不起作用。

我的应用使用nanohttpd为mediaPlayer制作流。

原生方法:

c = df.loc[df.a == 'c', 'a']
d = df.loc[df.a == 'c', 'b']

In [15]: c
Out[15]:
0     c
6     c
11    c
16    c
Name: a, dtype: object

In [16]: d
Out[16]:
0     0
6     0
11    0
16    0
Name: b, dtype: int64

变量:

public  native  String LH();
public  native  int P();
public  native  String EngineGS(Context context);
public  native  byte[] OGB(byte[] inputBuff);

nanohttpd类:

private MediaPlayer mp;
private HTTPServer encryptServer;

播放方法:

public class HTTPServer extends NanoHTTPD {

    public HTTPServer(int port) throws IOException {
        super(port);
        start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
    }

    @Override
    public Response serve(IHTTPSession session) {
        Response response = null;
        try {
            InputStream inputStream = new FileInputStream("/sdcard/Download/" + "encrypted.mp3");
            byte[] encryptedInputByteArray = IOUtils.toByteArray(inputStream);
            byte[] decryptedByteArray = OGB(encryptedInputByteArray);
            inputStream = new ByteArrayInputStream(decryptedByteArray);

            int totalLength = inputStream.available();

            String requestRange = session.getHeaders().get("range");
            if (requestRange == null) {
                response = NanoHTTPD.newFixedLengthResponse(Response.Status.OK, "audio/mpeg", inputStream, totalLength);
            } else {

                Matcher matcher = Pattern.compile("bytes=(\\d+)-(\\d*)").matcher(requestRange);
                matcher.find();
                long start = 0;
                try {
                    start = Long.parseLong(matcher.group(1));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                inputStream.skip(start);

                long restLength = totalLength - start;
                response = NanoHTTPD.newFixedLengthResponse(Response.Status.PARTIAL_CONTENT, "audio/mpeg", inputStream, restLength);

                String contentRange = String.format("bytes %d-%d/%d", start, totalLength, totalLength);
                response.addHeader("Content-Range", contentRange);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return response;
    }
}

我不知道问题出在哪里。

错误:

localhost

memtrack

我认为问题来自这里:

无内容提供商:http://localhost:8080

0 个答案:

没有答案