0

I'm using the OpenTok Android SDK and I'm trying to set the camera resolution to low to save on bandwidth. I've read all of the documentation about this, but it's not working as expected. Both the resolution and the frameRate remain the same.

    public class MainActivity extends AppCompatActivity
    implements EasyPermissions.PermissionCallbacks,
    WebServiceCoordinator.Listener,
    Session.SessionListener,
    PublisherKit.PublisherListener,
    SubscriberKit.SubscriberListener{

private static final String LOG_TAG = MainActivity.class.getSimpleName();
private static final int RC_SETTINGS_SCREEN_PERM = 123;
private static final int RC_VIDEO_APP_PERM = 124;

private WebServiceCoordinator mWebServiceCoordinator;

private Session mSession;
private Publisher mPublisher;
private FrameLayout mPublisherViewContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mPublisherViewContainer = (FrameLayout)findViewById(R.id.subscriber_container);
    requestPermissions();



}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}

@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {


}

@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {



    if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
        new AppSettingsDialog.Builder(this)
                .setTitle(getString(R.string.title_settings_dialog))
                .setRationale(getString(R.string.rationale_ask_again))
                .setPositiveButton(getString(R.string.setting))
                .setNegativeButton(getString(R.string.cancel))
                .setRequestCode(RC_SETTINGS_SCREEN_PERM)
                .build()
                .show();
    }
}

@AfterPermissionGranted(RC_VIDEO_APP_PERM)
private void requestPermissions() {

    String[] perms = { Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO };
    if (EasyPermissions.hasPermissions(this, perms)) {
        if (OpenTokConfig.CHAT_SERVER_URL == null) {
            if (OpenTokConfig.areHardCodedConfigsValid()) {
                initializeSession(OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID, OpenTokConfig.TOKEN);
            } else {
                showConfigError("Configuration Error", OpenTokConfig.hardCodedConfigErrorMessage);
            }
        } else {
            if (OpenTokConfig.isWebServerConfigUrlValid()) {
                mWebServiceCoordinator = new WebServiceCoordinator(this, this);
                mWebServiceCoordinator.fetchSessionConnectionData(OpenTokConfig.SESSION_INFO_ENDPOINT);
            } else {
                showConfigError("Configuration Error", OpenTokConfig.webServerConfigErrorMessage);
            }
        }
    } else {
        EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), RC_VIDEO_APP_PERM, perms);
    }
}

private void initializeSession(String apiKey, String sessionId, String token) {

    mSession = new Session.Builder(this, apiKey, sessionId).build();
    mSession.setSessionListener(this);
    mSession.connect(token);
}


@Override
public void onSessionConnectionDataReady(String apiKey, String sessionId, String token) {

    initializeSession(apiKey, sessionId, token);
}


@Override
public void onWebServiceCoordinatorError(Exception error) {


}


@Override
public void onConnected(Session session) {


    mPublisher = new Publisher.Builder(this)
            .resolution(Publisher.CameraCaptureResolution.LOW)
            .frameRate(Publisher.CameraCaptureFrameRate.FPS_15)


            .audioTrack(false)
            .build();
    mPublisher.setPublisherListener(this);

    mPublisher.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE,
            BaseVideoRenderer.STYLE_VIDEO_FILL);
    mPublisherViewContainer.addView(mPublisher.getView());
    if (mPublisher.getView() instanceof GLSurfaceView) {
        ((GLSurfaceView) mPublisher.getView()).setZOrderOnTop(true);
    }

    mSession.publish(mPublisher);

}

@Override
public void onDisconnected(Session session) {

}

@Override
public void onStreamReceived(Session session, Stream stream) {

}

@Override
public void onStreamDropped(Session session, Stream stream) {


}

@Override
public void onError(Session session, OpentokError opentokError) {

    showOpenTokError(opentokError);
}


@Override
public void onStreamCreated(PublisherKit publisherKit, Stream stream) {


}

@Override
public void onStreamDestroyed(PublisherKit publisherKit, Stream stream) {

}

@Override
public void onError(PublisherKit publisherKit, OpentokError opentokError) {


    showOpenTokError(opentokError);
}

@Override
public void onConnected(SubscriberKit subscriberKit) {

}

@Override
public void onDisconnected(SubscriberKit subscriberKit) {

}

@Override
public void onError(SubscriberKit subscriberKit, OpentokError opentokError) {

    showOpenTokError(opentokError);
}

private void showOpenTokError(OpentokError opentokError) {

    Toast.makeText(this, opentokError.getErrorDomain().name() +": " +opentokError.getMessage() + " Что-то не так.", Toast.LENGTH_LONG).show();
}

private void showConfigError(String alertTitle, final String errorMessage) {
    Log.e(LOG_TAG, "Error " + alertTitle + ": " + errorMessage);
    new AlertDialog.Builder(this)
            .setTitle(alertTitle)
            .setMessage(errorMessage)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    MainActivity.this.finish();
                }
            })
            .setIcon(android.R.drawable.ic_dialog_alert)
            .show();
}

}

Just nothing happens.

Why? You can help me?

In official documentation https://tokbox.com/developer/guides/audio-video/android/#resolution-frame-rate

this working...

UPD: Added all code in my questions.

Dave Neeley
  • 3,526
  • 1
  • 24
  • 42
user300058
  • 21
  • 5
  • Please provide more information in order to understand what the problem is. If nothing happens, it means that your onConnected method is not getting invoked. Share more relevant code. – vivek verma Jun 11 '18 at 21:32
  • @vivekverma, added all code – user300058 Jun 11 '18 at 22:15
  • TokBox Developer Evangelist here. Can you verify how you're confirming if the `resolution` and `frameRate` are being set? Are you using the [Session Inspector Tool](https://tokbox.com/developer/tools/inspector_doc/)? – Manik Jun 13 '18 at 22:40
  • @Manik, Resolution and frame rate do not change because the quality of the picture does not change with the subscriber. Just nothing changes. FPS as it was and remains unchanged. The same thing happens with the resolution. No, i dont use Session Inspector Tool. – user300058 Jun 14 '18 at 07:29

0 Answers0