Skip to end of metadata
Go to start of metadata

A many operations requires a time while publishing video, for example, Websocket connection establishing and WebRTC publishing itself. It is recommended to lock excessive user actons like repeated clicks until the device enters the next stable state.

To do this, create muteButton method to disable all the keys used, for example

code

    private void muteButton() {
        mStartButton.setEnabled(false);
        mTestButton.setEnabled(false);
        mSwitchCameraButton.setEnabled(false);
        mSwitchFlashlightButton.setEnabled(false);
        mSwitchRendererButton.setEnabled(false);
    }

and unmuteButton method to enable all the keys

code

    private void unmuteButton() {
        mStartButton.setEnabled(true);
        mSwitchCameraButton.setEnabled(true);
        mSwitchRendererButton.setEnabled(true);
        if (mSendVideo.isChecked()) {
            mSwitchCameraButton.setEnabled(true);
        }
        if (Flashphoner.isFlashlightSupport()) {
            mSwitchFlashlightButton.setEnabled(true);
        }
    }

Then these methods should be called:

  • muteButton() - at operation start
  • umuteButton() - at operation end

For example, when user switches a camera used, muteButton should be called after Switch Camera key pressing, and unmuteButton should be called after camera is switched successfully, or switching failed due to some error

code

        mSwitchCameraButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (publishStream != null) {
                    turnOffFlashlight();
                    muteButton();
                    publishStream.switchCamera(new CameraSwitchHandler() {
                        @Override
                        public void onCameraSwitchDone(boolean var1) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (mStartButton.getTag() == null || Integer.valueOf(R.string.action_stop).equals(mStartButton.getTag())) {
                                        unmuteButton();
                                    }
                                }
                            });
                        }

                        @Override
                        public void onCameraSwitchError(String var1) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    unmuteButton();
                                }
                            });
                        }
                    });
                }
            }
        });
  • No labels