设置OpenTok分辨率和帧速率

时间:2018-06-11 21:29:08

标签: java android opentok tokbox

我正在使用OpenTok Android SDK,我正在尝试将相机分辨率设置为低以节省带宽。我已经阅读了有关此内容的所有文档,但它没有按预期工作。 resolutionframeRate都保持不变。

    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();
}

}

没有任何反应。

为什么呢?你能帮帮我吗?

在官方文档中https://tokbox.com/developer/guides/audio-video/android/#resolution-frame-rate

这工作......

UPD:在我的问题中添加了所有代码。

0 个答案:

没有答案