Publisher

public class Publisher extends PublisherKit

Used to capture an audio-video stream from the device's microphone and camera for use in an OpenTok session. Create a Publisher instance by calling the Publisher constructor.

When the view of a Publisher leaves the active window, the Publisher object is destroyed. This is the case for an activity that is stopped or paused.

Nested types: Publisher.CameraCaptureResolution, Publisher.CameraCaptureFrameRate, Publisher.CameraListener, Publisher.Builder

Properties

Name Type Description
cameraFrameRate Publisher.CameraCaptureFrameRate protected
cameraResolution Publisher.CameraCaptureResolution protected
cameraListener Publisher.CameraListener protected

Methods

Name Description
Publisher(builder)
cycleCamera() Cycles between cameras, if there are multiple cameras on the device.
getCameraId() → {int} Returns the currently active camera ID.
onCameraChanged(newCameraId) Invoked when the publisher changes the active camera.
onCameraError(error) Invoked when there is an error accessing the camera.
setCameraId(cameraId) Sets the desired camera.
setCameraListener(listener) Sets a CameraListener object to monitor when the camera used by the publisher changes.
setCameraTorch(enable) Sets the preferred flashlight (torch) mode for the camera.
setCameraZoomFactor(cameraZoomFactor) The preferred zoom factor (ratio) for the camera.
startPreview() From version 2.17.0 on, this method doesn't do anything.
swapCamera() This method is deprecated.

Publisher(builder)

Parameters:
Name Type Description
builder Publisher.Builder

cycleCamera()

Cycles between cameras, if there are multiple cameras on the device. When the camera used by the Publisher changes, the Publisher.CameraListener#onCameraChanged(Publisher publisher, int newCameraId) method is called.

getCameraId() → {int}

Returns the currently active camera ID. This value is either 0 (for the back-facing camera) or 1 (for the front-facing camera). If setCameraId(int) is never called, the return value is 1 (for the front-facing camera).

This method is deprecated. You should use the new cycleCamera() method to cycle between cameras, if there are multiple cameras on the device.

Deprecated

Returns:

int

onCameraChanged(newCameraId)

Invoked when the publisher changes the active camera.

If you extend the Publisher class, you can override this method instead of the onCameraChanged() method of the Publisher.CameraListener interface.

Parameters:
Name Type Description
newCameraId int The ID of the new active camera.

onCameraError(error)

Invoked when there is an error accessing the camera.

Parameters:
Name Type Description
error OpentokError The error.

setCameraId(cameraId)

Sets the desired camera. cameraId can be a value between 0 and android.hardware.Camera#getNumberOfCameras() - 1.

When the camera used by the Publisher changes, the Publisher.CameraListener#onCameraChanged(Publisher publisher, int newCameraId) method is called.

This method is deprecated. You should use the new cycleCamera() method to cycle between cameras, if there are multiple cameras on the device.

Deprecated

Parameters:
Name Type Description
cameraId int the id of the camera you want to use on this publisher

setCameraListener(listener)

Sets a CameraListener object to monitor when the camera used by the publisher changes.

Parameters:
Name Type Description
listener Publisher.CameraListener The CameraListener instance.

setCameraTorch(enable)

Sets the preferred flashlight (torch) mode for the camera. Note that this is a preference and may not take effect if the active camera does not support flashlight functionality (for example, the front camera typically does not support a flashlight).

Parameters:
Name Type Description
enable boolean The default value is false. Passing true or false indicates whether the publisher should enable or disable the camera's flashlight when available.

setCameraZoomFactor(cameraZoomFactor)

The preferred zoom factor (ratio) for the camera. A value of 1.0 represents no zoom (the default view). The value ranges from 0.5 to the maximum zoom factor. Values between 0.5 and 1.0 represent ultra-wide-angle (zoom out) and values between 1.0 and the maximum zoom factor represent zooming in. The actual zoom factor applied is automatically clamped to the range supported by the active camera’s configuration — if the camera does not support ultra-wide-angle, zoom factors set below 1.0 will not take effect and no zoom will be applied. For values over the maximum zoom factor supported by the camera, the zoom factor will be set with the max value. If the publisher camera is enabled, getting this property returns the current zoom factor; if the publisher camera is not enabled, getting this property returns the preferred zoom factor.

Parameters:
Name Type Description
cameraZoomFactor float Setting this property indicates the desired level of zoom, where a value of 1.0 represents no zoom (the default view).

startPreview()

From version 2.17.0 on, this method doesn't do anything. As soon as the Publisher object is created the camera's video is displayed in the Publisher's view. This change makes the behaviour consistent across OpenTok client SDKs.

Deprecated

swapCamera()

This method is deprecated. You should use the new cycleCamera() method to cycle between cameras, if there are multiple cameras on the device.

If you are using a custom video capturer, implement the BaseVideoCapturer.CaptureSwitch interface in the object that extends BaseVideoCapturer, and implement the BaseVideoCapturer.CaptureSwitch#swapCamera(int cameraId) method to define the behavior of the Publisher.swapCamera() method.

Deprecated