Theta SC2 Livepreview not working in Android

Hello Developers,
I have Ricoh theta S,V and SC2 for developing the app with 360 camera capturing facilities, for these implementation we used in androidhttps://github.com/ricohapi/theta-api2.1-android-sdk

Now our application can easily capture 360 image from theta S,V, but there is some preview issues in SC2. sometime it works and sometime it doesn’t, so how we can resolve this issue?

While we debug the code we find out that we got exception on
readMJpegFrame() in MJpegInputStream and this method calls from MJpegView like bitmap = mMJpegInputStream.readMJpegFrame();

See this:

showing it is working on SC2 on Android, Google Pixel

Example streaming from SC2 to Windows using same code

Article explaining what needs to be done

Example working with Flutter

It’s a bit old. I had intended to update and improve it, but I never got around to it. I recently tested it and it does work with the older version of Flutter and .Dart. From the commits, it looks like the last time I updated it was Aug, 2020.

Thanks @craig for reply, but we used sdk for theta camera S, V and later and we used below method for live preview and its work for theta V but doen’t work for SC2

public InputStream getLivePreviewForV() throws IOException, JSONException {

        // set capture mode to image
        setImageCaptureMode();

        HttpURLConnection postConnection = createHttpConnection("POST", "/osc/commands/execute");
        JSONObject input = new JSONObject();
        InputStream is = null;

        try {
            // send HTTP POST
            input.put("name", "camera.getLivePreview");
            JSONObject parameters = new JSONObject();

            OutputStream os = postConnection.getOutputStream();
            os.write(input.toString().getBytes());
            postConnection.connect();
            os.flush();
            os.close();

            is = postConnection.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
            String errorMessage = null;
            InputStream es = postConnection.getErrorStream();
            try {
                if (es != null) {
                    String errorData = InputStreamToString(es);
                    JSONObject output = new JSONObject(errorData);
                    JSONObject errors = output.getJSONObject("error");
                    errorMessage = errors.getString("message");
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (JSONException e1) {
                e1.printStackTrace();
            } finally {
                if (es != null) {
                    try {
                        es.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
            throw e;
        } catch (JSONException e) {
            e.printStackTrace();
            throw e;
        }

        return is;
    }

The SDK you are using is broken on the SC2, but works on the S, V, Z1. To get it to work on the SC2, you need to repeatedly send the getLivePreview command again with the API whenever you get an EOF exception.

We can solved it by using our own logic for retry the LivePreview command again, once the preview fire the EOFException then we can catch it and fire the same command again after minor delay i.e. 0.5 second. It means you can fire command after 0.5 seconds when your first command failed.

2 Likes

Thank you for sharing this.