Class Publisher
- java.lang.Object
- 
- com.opentok.android.PublisherKit
- 
- com.opentok.android.Publisher
 
 
- 
- All Implemented Interfaces:
- java.util.Observer
 
 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. - See Also:
- Session.publish(PublisherKit publisher)
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classPublisher.BuilderUsed to build aPublisherobject.static classPublisher.CameraCaptureFrameRateDefines values for theframeRateparameter of thePublisher.Builder.frameRate(Publisher.CameraCaptureFrameRate frameRate)method.static classPublisher.CameraCaptureResolutionDefines values for theresolutionparameter of thePublisher.Builder.resolution(Publisher.CameraCaptureResolution resolution)method.static interfacePublisher.CameraListenerMonitors when the camera used by the publisher changes.- 
Nested classes/interfaces inherited from class com.opentok.android.PublisherKitPublisherKit.AudioLevelListener, PublisherKit.AudioStatsListener, PublisherKit.AudioTransformer, PublisherKit.CustomAudioTransformer, PublisherKit.CustomVideoTransformer, PublisherKit.MuteListener, PublisherKit.PublisherAudioStats, PublisherKit.PublisherKitVideoType, PublisherKit.PublisherListener, PublisherKit.PublisherRtcStats, PublisherKit.PublisherRtcStatsReportListener, PublisherKit.PublisherVideoStats, PublisherKit.VideoListener, PublisherKit.VideoStatsListener, PublisherKit.VideoTransformer
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected Publisher.CameraCaptureFrameRatecameraFrameRateprotected Publisher.CameraListenercameraListenerprotected Publisher.CameraCaptureResolutioncameraResolution- 
Fields inherited from class com.opentok.android.PublisherKitaudioLevelListener, audioStatsListener, capturer, context, handler, muteListener, publisherListener, renderer, rtcStatsReportListener, videoListener, videoStatsListener
 
- 
 - 
Constructor SummaryConstructors Modifier Constructor Description Publisher(android.content.Context context)Deprecated.Publisher(android.content.Context context, java.lang.String name)Deprecated.Publisher(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack)Deprecated.protectedPublisher(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer)Deprecated.protectedPublisher(android.content.Context context, java.lang.String name, boolean audioTrack, int maxAudioBitrate, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare)Deprecated.protectedPublisher(android.content.Context context, java.lang.String name, boolean audioTrack, int maxAudioBitrate, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare, boolean subscriberAudioFallback, boolean publisherAudioFallback)Creates a new Publisher object.Publisher(android.content.Context context, java.lang.String name, BaseVideoCapturer capturer)Deprecated.Publisher(android.content.Context context, java.lang.String name, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate)Deprecated.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcycleCamera()Cycles between cameras, if there are multiple cameras on the device.intgetCameraId()Deprecated.protected voidonCameraChanged(int newCameraId)Invoked when the publisher changes the active camera.protected voidonCameraError(OpentokError error)Invoked when there is an error accessing the camera.voidsetCameraId(int cameraId)Deprecated.voidsetCameraListener(Publisher.CameraListener listener)Sets aPublisher.CameraListenerobject to monitor when the camera used by the publisher changes.voidstartPreview()Deprecated.voidswapCamera()Deprecated.- 
Methods inherited from class com.opentok.android.PublisherKitdestroy, finalize, getAudioFallbackEnabled, getCapturer, getName, getPublishAudio, getPublishCaptions, getPublisherVideoType, getPublishVideo, getRenderer, getRtcStatsReport, getSession, getStream, getView, onAudioLevelUpdated, onError, onMuteForced, onPause, onRestart, onResume, onRtcStatsReport, onStop, onStreamCreated, onStreamDestroyed, setAudioFallbackEnabled, setAudioLevelListener, setAudioStatsListener, setAudioTransformers, setCapturer, setMuteListener, setName, setPublishAudio, setPublishCaptions, setPublisherListener, setPublisherVideoType, setPublishVideo, setRenderer, setRtcStatsReportListener, setStyle, setVideoListener, setVideoStatsListener, setVideoTransformers, update
 
- 
 
- 
- 
- 
Field Detail- 
cameraFrameRateprotected Publisher.CameraCaptureFrameRate cameraFrameRate 
 - 
cameraResolutionprotected Publisher.CameraCaptureResolution cameraResolution 
 - 
cameraListenerprotected Publisher.CameraListener cameraListener 
 
- 
 - 
Constructor Detail- 
Publisher@Deprecated public Publisher(android.content.Context context) Deprecated.Creates a new Publisher instance. Use theSession.publish(PublisherKit publisher)method to start streaming from this Publisher into a session.The PublisherKit.getView()method returns the android.view.View object containing the published video.- Parameters:
- context- The android.content.Context for the Publisher.
 
 - 
Publisher@Deprecated public Publisher(android.content.Context context, java.lang.String name)Deprecated.Creates a new Publisher instance. This method is deprecated. Use thePublisher.Builderclass to instantiate a Publisher object.Use the Session.publish(PublisherKit publisher)method to start streaming from this Publisher into a session.This version of the constructor lets you add a name for the publisher's stream. The PublisherKit.getView()method returns the android.view.View object containing the published video.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- nameproperty for a stream published by this publisher will be set to this value (on all clients).
 
 - 
Publisher@Deprecated public Publisher(android.content.Context context, java.lang.String name, BaseVideoCapturer capturer)Deprecated.Creates a new Publisher instance. This method is deprecated. Use thePublisher.Builderclass to instantiate a PublisherKit object.Use the Session.publish(PublisherKit publisher)method to start streaming from this Publisher into a session.This version of the constructor lets you define a custom video capturer for the Publisher. The PublisherKit.getView()method returns the android.view.View object containing the published video.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- Stream.getName()method for a stream published by this publisher will return this value (on all clients).
- capturer- The video capturer to use for the Publisher.
 
 - 
Publisher@Deprecated public Publisher(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack)Deprecated.Creates a new Publisher instance. This method is deprecated. Use thePublisher.Builderclass to instantiate a PublisherKit object.Use the Session.publish(PublisherKit publisher)method to start streaming from this Publisher into a session.This version of the constructor adds parameters that let you exclude the audio track or video track from the published stream. Creating a Publisher without an audio track or video track can save CPU resources. The PublisherKit.getView()method returns the android.view.View object containing the published video.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- Stream.getName()method for a stream published by this publisher will return this value (on all clients).
- audioTrack- Whether to include an audio track in the published stream.
- videoTrack- Whether to include a video track in the published stream.
 
 - 
Publisher@Deprecated public Publisher(android.content.Context context, java.lang.String name, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate)Deprecated.Creates a new Publisher instance. This method is deprecated. Use thePublisher.Builderclass to instantiate a PublisherKit object.Use the Session.publish(PublisherKit publisher)method to start streaming from this Publisher into a session.This version of the constructor adds parameters for setting the resolution and frame rate of the video. For sessions that use the OpenTok Media Router (sessions with the media mode set to routed), lowering the frame rate or lowering the resolution reduces the maximum bandwidth the stream can use. However, in sessions with the media mode set to relayed, lowering the frame rate or resolution may not reduce the stream's bandwidth. The PublisherKit.getView()method returns the android.view.View object containing the published video.Note: The default frame rate and resolution for a Publisher constructed using other versions of the Publisher constructor are set to Publisher.CameraCaptureFrameRate.FPS_30andPublisher.CameraCaptureResolution.MEDIUM. However, these can vary over time for the stream.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- Stream.getName()method for a stream published by this publisher will return this value (on all clients).
- resolution- The resolution of the video. Set this to a value defined in the- Publisher.CameraCaptureResolutionenum.
- frameRate- The frame rate of the video. Set this to a value defined in the- Publisher.CameraCaptureFrameRateenum. If the device does not support the specified frame rate, it will use the closest supported frame rate that is lower. Note that in sessions that use the OpenTok Media Router (sessions with the media mode set to routed), lowering the frame rate proportionally reduces the bandwidth the stream uses. However, in sessions that have the media mode set to relayed, lowering the frame rate does not reduce the stream's bandwidth. (See The OpenTok Media Router and media modes.)
 
 - 
Publisher@Deprecated protected Publisher(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer)Deprecated.Returns a newPublisherinstance based on thePublisher.Buildersettings.
 - 
Publisherprotected Publisher(android.content.Context context, java.lang.String name, boolean audioTrack, int maxAudioBitrate, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare, boolean subscriberAudioFallback, boolean publisherAudioFallback)Creates a new Publisher object. If you extend thePublisherclass, you can call this constructor from the child class.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- Stream.getName()method for a published by this publisher will return this value (on all clients).
- audioTrack- Whether to include an audio track in the published stream.
- maxAudioBitrate- The desired bitrate of the audio, in bits per second.
- videoTrack- Whether to include a video track in the published stream.
- capturer- The video capturer for the publisher.
- renderer- The video renderer for the publisher.
- enableOpusDtx- Whether to enable Opus DTX.
- scalableScreenshare- Whether to allow use of scalable video for a publisher that has the videoType set to PublisherKitVideoTypeScreen (true) or not (false, the default).
- subscriberAudioFallback- Whether the stream will use the subscriber audio-fallback feature (- true) or not
- publisherAudioFallback- Whether the stream will use the publisher audio-fallback feature (- true) or not
 
 - 
Publisher@Deprecated protected Publisher(android.content.Context context, java.lang.String name, boolean audioTrack, int maxAudioBitrate, boolean videoTrack, BaseVideoCapturer capturer, Publisher.CameraCaptureResolution resolution, Publisher.CameraCaptureFrameRate frameRate, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare)Deprecated.Creates a new Publisher object. If you extend thePublisherclass, you can call this constructor from the child class.- Parameters:
- context- The android.content.Context for the Publisher.
- name- The name of the publisher video. The- Stream.getName()method for a published by this publisher will return this value (on all clients).
- audioTrack- Whether to include an audio track in the published stream.
- maxAudioBitrate- The desired bitrate of the audio, in bits per second.
- videoTrack- Whether to include a video track in the published stream.
- capturer- The video capturer for the publisher.
- renderer- The video renderer for the publisher.
- enableOpusDtx- Whether to enable Opus DTX.
- scalableScreenshare- Whether to allow use of scalable video for a publisher that has the videoType set to PublisherKitVideoTypeScreen (true) or not (false, the default).
 
 
- 
 - 
Method Detail- 
setCameraListenerpublic void setCameraListener(Publisher.CameraListener listener) Sets aPublisher.CameraListenerobject to monitor when the camera used by the publisher changes.- Parameters:
- listener- The- Publisher.CameraListenerinstance.
 
 - 
setCameraId@Deprecated public void setCameraId(int cameraId) Deprecated.Sets the desired camera.cameraIdcan be a value between 0 and android.hardware.Camera#getNumberOfCameras() - 1.When the camera used by the Publisher changes, the This method is deprecated. You should use the newPublisher.CameraListener.onCameraChanged(Publisher publisher, int newCameraId)method is called.cycleCamera()method to cycle between cameras, if there are multiple cameras on the device.- Parameters:
- cameraId- the id of the camera you want to use on this publisher
 
 - 
cycleCamerapublic void cycleCamera() Cycles between cameras, if there are multiple cameras on the device. When the camera used by the Publisher changes, thePublisher.CameraListener.onCameraChanged(Publisher publisher, int newCameraId)method is called.
 - 
swapCamera@Deprecated public void swapCamera() Deprecated.This method is deprecated. You should use the newcycleCamera()method to cycle between cameras, if there are multiple cameras on the device.If you are using a custom video capturer, implement the BaseVideoCapturer.CaptureSwitchinterface in the object that extends BaseVideoCapturer, and implement theBaseVideoCapturer.CaptureSwitch.swapCamera(int cameraId)method to define the behavior of thePublisher.swapCamera()method.
 - 
getCameraId@Deprecated public int getCameraId() Deprecated.Returns the currently active camera ID. This value is either 0 (for the back-facing camera) or 1 (for the front-facing camera). IfsetCameraId(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.
 - 
onCameraChangedprotected void onCameraChanged(int 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:
- newCameraId- The ID of the new active camera.
 
 - 
onCameraErrorprotected void onCameraError(OpentokError error) Invoked when there is an error accessing the camera.- Parameters:
- error- The error.
 
 - 
startPreview@Deprecated public void startPreview() Deprecated.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.
 
- 
 
-