Class PublisherKit
- All Implemented Interfaces:
Observer
- Direct Known Subclasses:
Publisher
Session.publish(PublisherKit publisher) method.
Create a subclass of PublisherKit if you are interested in providing your own
video capturing and rendering implementation. Otherwise, use the Publisher
class, which includes a pre-built video capturer and renderer.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceMonitors changes in the audio level of the publisher.static interfaceDefines the listener object for getting publisher audio statistics.classA transformer for an audio stream.static classUsed to build aPublisherKitobject.static interfaceDefines a custom transformer for an audio stream, to be passed into thePublisherKit.AudioTransformerconstructor.static interfaceDefines a custom transformer for a video stream, to be passed into thePublisherKit.VideoTransformerconstructor.static interfaceMonitors when a moderator has forced this publisher to mute audio.static classDefines audio statistics for a publisher.static enumDefines values for thesetPublisherVideoType(PublisherKitVideoType type)method.static interfaceMonitors when a publisher starts and stops streaming to the session.static classRepresents RTC statistics for a media stream published by the publisher.static interfaceDefines the listener object for getting publisher RTC stats reports.static classDefines video statistics for a publisher.static enumDefines values for thesetVideoBitratePreset(VideoBitratePreset preset)method.static interfaceMonitors when the publisher starts and stops receiving video data.static interfaceDefines the listener object for getting publisher video statistics.classA transformer for a video stream. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PublisherKit.AudioLevelListenerprotected PublisherKit.AudioStatsListenerprotected BaseVideoCapturerprotected android.content.Contextprotected android.os.Handlerprotected PublisherKit.MuteListenerprotected PublisherKit.PublisherListenerprotected BaseVideoRendererprotected PublisherKit.VideoListenerprotected PublisherKit.VideoStatsListener -
Constructor Summary
ConstructorsModifierConstructorDescriptionPublisherKit(android.content.Context context) Deprecated.PublisherKit(android.content.Context context, String name) Deprecated.PublisherKit(android.content.Context context, String name, boolean audioTrack, boolean videoTrack) Deprecated.protectedPublisherKit(android.content.Context context, String name, boolean audioTrack, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer) Deprecated.protectedPublisherKit(android.content.Context context, String name, boolean audioTrack, int maxAudioBitRate, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare) Deprecated.protectedPublisherKit(android.content.Context context, String name, boolean audioTrack, int maxAudioBitRate, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare, boolean subscriberAudioFallback, boolean publisherAudioFallback, boolean allowAudioCaptureWhileMuted) Creates a new PublisherKit object. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Releases this object, including all hardware and UI resources bound to it, if it cannot be released by the garbage collector.protected voidfinalize()Called by the garbage collector when it determines that there are no more references to the PublisherKit object.booleanDeprecated.Returns the video capturer used by this publisher.intGets the maximum video bitrate for the publisher's video stream, in bits per second.getName()The stream name.booleanWhether the Publisher is publishing audio (true) or not (false).booleanWhether the Publisher is publishing captions (true) or not (false).Returns the type of video for this publisher.booleanWhether the Publisher is publishing video (true) or not (false).Returns the video renderer for this publisher.voidGets the RTC stats report for the publisher.Returns theSessionbound to this Publisher instance.Returns the stream object corresponding the the Publisher's stream.Gets the currently active video bitrate preset for the publisher's stream.android.view.ViewgetView()Returns the android.view.View object that contains the Publisher video.protected voidonAudioLevelUpdated(float audioLevel) Called periodically to report the audio level of the publisher.protected voidonError(OpentokError error) Invoked when the publisher fails.protected voidInvoked when a moderator has forced this publisher to mute audio.voidonPause()Do not call directly; callSession.onPause()instead.voidRestarts publisher resources that were previously released by calling theonStop()method.voidonResume()Do not call directly; callSession.onResume()instead.protected voidCalled when the publisher's RTC stats report is available in response to a call togetRtcStatsReport().voidonStop()Releases resources tied to the publisher.protected voidonStreamCreated(Stream stream) Invoked when the publisher's stream is created.protected voidonStreamDestroyed(Stream stream) Invoked when the publisher's stream is destroyed.voidsetAudioFallbackEnabled(boolean enabled) Deprecated.voidBinds anPublisherKit.AudioLevelListenerto this PublisherKit instance to monitor audio level updates.voidSets up a listener for publisher audio statistics.voidsetAudioTransformers(ArrayList<PublisherKit.AudioTransformer> audioTransformers) Sets a list of audio transformers to this publisher's audio stream.voidsetCapturer(BaseVideoCapturer newCapturer) Deprecated.voidsetMaxVideoBitrate(int maxVideoBitrate) Sets the maximum video bitrate for the publisher's video stream, in bits per second.voidsetMuteListener(PublisherKit.MuteListener listener) Sets aPublisherKit.MuteListenerobject to monitor when a moderator forces this publisher to mute audio.voidDeprecated.voidsetPublishAudio(boolean publishAudio) Toggles publishing of audio on or off, based on the value passed in.voidsetPublishCaptions(boolean publishCaptions) Toggles publishing of captioning on or off, based on the value passed in.voidBinds aPublisherKit.PublisherListenerto this Publisher instance to monitor state changes.voidSpecifies the type of video for this stream.voidsetPublishVideo(boolean publishVideo) Toggles publishing of video on or off, based on the value passed in.voidsetRenderer(BaseVideoRenderer renderer) Deprecated.voidSets the RTC stats report listener the subscriber.voidSets a style for the video renderer used by this publisher.voidsetVideoBitratePreset(PublisherKit.VideoBitratePreset videoBitratePreset) Sets a video bitrate preset strategy for the publisher's video stream.voidsetVideoListener(PublisherKit.VideoListener listener) Sets aPublisherKit.VideoListenerobject to monitor when the publisher starts and stops sending video.voidSets up a listener for publisher video statistics.voidsetVideoTransformers(ArrayList<PublisherKit.VideoTransformer> videoTransformers) Sets a list of video transformers to this publisher's video stream.voidupdate(Observable o, Object arg) Deprecated.
-
Field Details
-
handler
protected android.os.Handler handler -
publisherListener
-
audioLevelListener
-
videoStatsListener
-
audioStatsListener
-
muteListener
-
rtcStatsReportListener
-
context
protected android.content.Context context -
renderer
-
capturer
-
videoListener
-
-
Constructor Details
-
PublisherKit
@Deprecated protected PublisherKit(android.content.Context context, String name, boolean audioTrack, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer) Deprecated.Creates a new PublisherKit instance. If you extend thePublisherKitclass, you can call this constructor to instantiate a publisher object.Use the
Session.publish(PublisherKit publisher)method to start streaming from this publisher into a session.The
getView()method returns the android.view.View object containing the published video.Publishers cannot be reused. Instantiate a new
PublisherKitobject each time you want to publish a new stream.- Parameters:
context- The android.content.Context for the Publisher.name- The name of the publisher video. TheStream.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.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.- See Also:
-
PublisherKit
@Deprecated protected PublisherKit(android.content.Context context, String name, boolean audioTrack, int maxAudioBitRate, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare) Deprecated.Creates a new PublisherKit object. If you extend thePublisherKitclass, 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. TheStream.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.scalableScreenshare- Whether to allow use of scalable video for a publisher that has the videoType set to PublisherKitVideoTypeScreen (true) or not (false, the default).
-
PublisherKit
protected PublisherKit(android.content.Context context, String name, boolean audioTrack, int maxAudioBitRate, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare, boolean subscriberAudioFallback, boolean publisherAudioFallback, boolean allowAudioCaptureWhileMuted) Creates a new PublisherKit object. If you extend thePublisherKitclass, 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. TheStream.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.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 notpublisherAudioFallback- Whether the stream will use the publisher audio-fallback feature (true) or not
-
PublisherKit
@Deprecated public PublisherKit(android.content.Context context, String name, boolean audioTrack, boolean videoTrack) Deprecated.Creates a new PublisherKit instance. This method is deprecated. Use thePublisherKit.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
getView()method returns the android.view.View object containing the published video.Publishers cannot be reused.
- Parameters:
context- The android.content.Context for the Publisher.name- The name of the publisher video. TheStream.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.
-
PublisherKit
Deprecated.Creates a new PublisherKit instance. This method is deprecated. Use thePublisherKit.Builderclass to instantiate a PublisherKit object.Use the
Session.publish(PublisherKit publisher)method to start streaming from this publisher into a session.The
getView()method returns the android.view.View object containing the published video.- Parameters:
context- The android.content.Context for the Publisher.- See Also:
-
PublisherKit
Deprecated.Creates a new PublisherKit instance. This method is deprecated. Use thePublisherKit.Builderclass to instantiate a PublisherKit object.Use the
Session.publish(PublisherKit publisher)method to start streaming from this publisher into a session.The
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. TheStream.getName()method for a stream published by this publisher will return this value (on all clients).- See Also:
-
-
Method Details
-
onPause
public void onPause()Do not call directly; callSession.onPause()instead. -
onResume
public void onResume()Do not call directly; callSession.onResume()instead. -
destroy
public void destroy()Releases this object, including all hardware and UI resources bound to it, if it cannot be released by the garbage collector. Resources are generally safely released by the garbage collector, and you do not need to call this method. However, this can happen at any time at the VM discretion, which might not be the desired behavior in some cases. This method allows manually releasing resources for scenarios where immediateness is desired:- An app wants to publish again but needs to have access to the camera immediately after unpublishing.
- An app wants to make sure that the audio device is released immediately after unpublishing.
After you have called this method, you cannot reuse the publisher.
-
setPublishVideo
public void setPublishVideo(boolean publishVideo) Toggles publishing of video on or off, based on the value passed in.- Parameters:
publishVideo- Whether to publish video (true) or not (false).
-
setPublishAudio
public void setPublishAudio(boolean publishAudio) Toggles publishing of audio on or off, based on the value passed in.- Parameters:
publishAudio- Whether to publish audio (true) or not (false).
-
setPublishCaptions
public void setPublishCaptions(boolean publishCaptions) Toggles publishing of captioning on or off, based on the value passed in.- Parameters:
publishCaptions- Whether to publish captions (true) or not (false).
-
setName
Deprecated.Set the name for this stream. The name appears at the bottom of the publisher video and at the bottom of subscriber videos associated with the published stream. You can set this name after initializing the publisher and before thePublisherKit.PublisherListener.onStreamCreated(PublisherKit publisher, Stream stream)method is called. Setting the property after thePublisherKit.PublisherListener.onStreamCreated(PublisherKit publisher, Stream stream)method is called has no effect on the name displayed for the stream.The default name is "" (an empty string).
-
setPublisherVideoType
Specifies the type of video for this stream. Set this to one of the following values:PublisherKitVideoType.PublisherKitVideoTypeScreen— Optimizes the video encoding for screen sharing. It is recommended to use a low frame rate (5 frames per second or lower) with this video type. When using the screen video type in a session that uses the OpenTok Media Server, you should call thesetAudioFallbackEnabled(boolean enabled)method and pass infalsebefore calling theSession.publish(com.opentok.android.PublisherKit)method; this disables the audio-only fallback feature, so that the video does not drop out in subscribers. See The OpenTok Media Router and media modes.PublisherKitVideoType.PublisherKitVideoTypeCamera— This is the default setting, which you should use when using a camera as the video source.
-
getName
The stream name. The name appears at the bottom of Subscriber videos.- Returns:
- publisher name
-
getPublishVideo
public boolean getPublishVideo()Whether the Publisher is publishing video (true) or not (false). -
getPublishAudio
public boolean getPublishAudio()Whether the Publisher is publishing audio (true) or not (false). -
getPublishCaptions
public boolean getPublishCaptions()Whether the Publisher is publishing captions (true) or not (false). -
getSession
Returns theSessionbound to this Publisher instance.- Returns:
- The
Sessionbound to this Publisher instance. - See Also:
-
getStream
Returns the stream object corresponding the the Publisher's stream.- Returns:
- The stream object.
-
getPublisherVideoType
Returns the type of video for this publisher.- See Also:
-
getMaxVideoBitrate
public int getMaxVideoBitrate()Gets the maximum video bitrate for the publisher's video stream, in bits per second.Returns the currently configured upper limit. If no manual bitrate has been set, or if a bitrate preset is active, the value is 0.
- Returns:
- The maximum video bitrate in bits per second, or 0 if unset or using a preset.
- See Also:
-
setMaxVideoBitrate
public void setMaxVideoBitrate(int maxVideoBitrate) Sets the maximum video bitrate for the publisher's video stream, in bits per second.This method applies an explicit upper limit to the publisher’s video bitrate. Setting the value to 0 clears any manual cap and reverts to the default preset-based adaptive bitrate behavior with no explicit limit.
- Parameters:
maxVideoBitrate- The maximum video bitrate in bits per second, between 5,000 and 10,000,000.- See Also:
-
getVideoBitratePreset
Gets the currently active video bitrate preset for the publisher's stream.Returns the preset strategy in use. If a custom bitrate has been manually set using
setMaxVideoBitrate(int), this method returnsPublisherKit.VideoBitratePreset.VideoBitratePresetCustom.- Returns:
- The active
PublisherKit.VideoBitratePreset. - See Also:
-
setVideoBitratePreset
Sets a video bitrate preset strategy for the publisher's video stream.Preset configurations balance video quality and bandwidth usage with predefined strategies. Preset settings and manual bitrate settings are mutually exclusive. Setting the
setMaxVideoBitrate(int)method overrides any preset and automatically changes the active preset toPublisherKit.VideoBitratePreset.VideoBitratePresetCustom.Note: The
PublisherKit.VideoBitratePreset.VideoBitratePresetCustomvalue cannot be set directly.- Parameters:
videoBitratePreset- ThePublisherKit.VideoBitratePresetto apply.- See Also:
-
setPublisherListener
Binds aPublisherKit.PublisherListenerto this Publisher instance to monitor state changes.- Parameters:
listener- ThePublisherKit.PublisherListenerthat will monitor this instance, or null to disconnect a listener.
-
setAudioLevelListener
Binds anPublisherKit.AudioLevelListenerto this PublisherKit instance to monitor audio level updates.- Parameters:
listener- ThePublisherKit.AudioLevelListenerthat will monitor this instance. Set this to null to disconnect a listener and stop monitoring audio levels.
-
setRtcStatsReportListener
Sets the RTC stats report listener the subscriber. SeegetRtcStatsReport().- Parameters:
listener- ThePublisherKit.PublisherRtcStatsReportListenerobject.
-
setVideoTransformers
Sets a list of video transformers to this publisher's video stream. If the list is empty, calling this method resets the transformers. The array can be composed by Vonage video transformers provided by ml-library or custom transfomers (see this developer guide). Note: Media transformers are not supported on all devices or Android versions. See this documentation.- Parameters:
videoTransformers- The list of video transformers, in the order to be applied to the stream.
-
setVideoListener
Sets aPublisherKit.VideoListenerobject to monitor when the publisher starts and stops sending video.- Parameters:
listener- ThePublisherKit.VideoListenerinstance.
-
setAudioTransformers
Sets a list of audio transformers to this publisher's audio stream. If the list is empty, calling this method resets the transformers. The array can be composed of Vonage audio transformers provided by ml-library or custom transfomers (see this developer guide). Note: Media transformers are not supported on all devices or Android versions. See this documentation. .- Parameters:
audioTransformers- The list of audio transformers, in the order to be applied to the stream.
-
setStyle
Sets a style for the video renderer used by this publisher.By default, there is only one pre-defined style key:
BaseVideoRenderer.STYLE_VIDEO_SCALE. You can set a value for this key to determine the scaling of the video. The following values are supported:-
BaseVideoRenderer.STYLE_VIDEO_FILL— The video scales to fill the entire area of the renderer, with cropping as needed. -
BaseVideoRenderer.STYLE_VIDEO_FIT— The video shrinks, as needed, so that the entire video is visible, with pillarboxing. If you do not set this style the default setting isBaseVideoRenderer.STYLE_VIDEO_FIT.
Calling this method is equivalent to calling
getRenderer().setStyle(). However, if you extend this class, you can override this method to support other styles and behaviors.- Parameters:
key- The style to set.value- The value you are setting the style to.
-
-
setRenderer
Deprecated.Sets the video renderer for this publisher.This method is deprecated. Instead, call the
PublisherKit.Builder.renderer(BaseVideoRenderer renderer)method when using the Builder to create the PublisherKit instance. -
getRenderer
Returns the video renderer for this publisher. -
getCapturer
Returns the video capturer used by this publisher. -
setCapturer
Deprecated.Sets the video capturer for this publisher.This method is deprecated. Instead, call the
PublisherKit.Builder.capturer(BaseVideoCapturer capturer)method when using the builder to create the PublisherKit instance. -
getView
public android.view.View getView()Returns the android.view.View object that contains the Publisher video. -
setVideoStatsListener
Sets up a listener for publisher video statistics. The listener object implements thePublisherKit.VideoStatsListener.onVideoStats(PublisherKit publisher, PublisherKit.PublisherVideoStats[] stats)method. This method is called periodically to report the following:- Total video packets lost
- Total video packets sent
- Total video bytes sent
- See Also:
-
setAudioStatsListener
Sets up a listener for publisher audio statistics. The listener object implements thePublisherKit.AudioStatsListener.onAudioStats(PublisherKit publisher, PublisherKit.PublisherAudioStats[] stats)method. This method is called periodically to report the following:- Total audio packets lost
- Total audio packets sent
- Total audio bytes sent
- See Also:
-
setMuteListener
Sets aPublisherKit.MuteListenerobject to monitor when a moderator forces this publisher to mute audio.- Parameters:
listener- ThePublisherKit.MuteListenerinstance.
-
setAudioFallbackEnabled
Deprecated.Whether the stream will use the subscriber audio-fallback feature (true) or not (false). The audio-fallback feature is available in sessions that use the the OpenTok Media Router. With the audio-fallback feature enabled (the default), when the OpenTok Media Router determines that a stream's quality has degraded significantly for a specific subscriber, it disables the video in that subscriber in order to preserve audio quality.The default setting is
true(the audio-fallback feature is enabled). To turn off the audio-fallback feature, call this method (and pass infalse) before calling theSession.publish(com.opentok.android.PublisherKit)method.- See Also:
-
getAudioFallbackEnabled
Deprecated.Whether the stream uses the subscriber audio-fallback feature (true) or not (false).- See Also:
-
getRtcStatsReport
public void getRtcStatsReport()Gets the RTC stats report for the publisher. This is an asynchronous operation. Call thesetRtcStatsReportListener(PublisherKit.PublisherRtcStatsReportListener listener)method, and then implement thePublisherKit.PublisherRtcStatsReportListener.onRtcStatsReport(PublisherKit publisher, PublisherKit.PublisherRtcStats[] stats)method prior to calling this method. When the stats are available, the implementation of thePublisherKit.PublisherRtcStatsReportListener.onRtcStatsReport(PublisherKit publisher, PublisherKit.PublisherRtcStats[] stats)method is called.Also see
setAudioStatsListener(PublisherKit.AudioStatsListener listener),setVideoStatsListener(PublisherKit.VideoStatsListener listener), andSubscriberKit.getRtcStatsReport(). -
onRtcStatsReport
Called when the publisher's RTC stats report is available in response to a call togetRtcStatsReport().If you extend the PublisherKit class, you can override this method instead of implementing the onRtcStatsReport() method of the PublisherKit.PublisherRtcStatsReportListener interface.
- See Also:
-
onStreamCreated
Invoked when the publisher's stream is created.If you extend the PublisherKit class, you can override this method instead of the
onStreamCreated()method of the PublisherKit.PublisherListener interface.- Parameters:
stream- The stream that that is created.
-
onStreamDestroyed
Invoked when the publisher's stream is destroyed.If you extend the PublisherKit class, you can override this method instead of the
onStreamDestroyed()method of the PublisherKit.PublisherListener interface.- Parameters:
stream- The stream that that is destroyed.
-
onError
Invoked when the publisher fails.If you extend the PublisherKit class, you can override this method instead of the
onError()method of the PublisherKit.PublisherListener interface.- Parameters:
error- The error that invoked this callback.
-
onAudioLevelUpdated
protected void onAudioLevelUpdated(float audioLevel) Called periodically to report the audio level of the publisher.- Parameters:
audioLevel- The audio level, from 0 to 1.0. Adjust this value logarithmically for use in a user interface visualization (such as a volume meter).
-
onMuteForced
protected void onMuteForced()Invoked when a moderator has forced this publisher to mute audio.If you extend the PublisherKit class, you can override this method instead of the
onMuteForced()method of the PublisherKit.MuteListener interface. -
update
Deprecated.This method is called whenever the observed object is changed. This class implements the Observer interface, so it observes events, such as the session pause and session resume events. -
finalize
Called by the garbage collector when it determines that there are no more references to the PublisherKit object. -
onStop
public void onStop()Releases resources tied to the publisher. Calling this method causes the publisher to stop capturing, and then it releases the camera. To reuse the publisher after calling this method, call theonRestart()method. -
onRestart
public void onRestart()Restarts publisher resources that were previously released by calling theonStop()method.
-