public class PublisherKit
extends java.lang.Object
implements java.util.Observer
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.
Modifier and Type | Class and Description |
---|---|
static interface |
PublisherKit.AudioLevelListener
Monitors changes in the audio level of the publisher.
|
static interface |
PublisherKit.AudioStatsListener
Defines the listener object for getting publisher audio statistcs.
|
static class |
PublisherKit.Builder
Used to build a
PublisherKit object. |
static interface |
PublisherKit.MuteListener
Monitors when a moderator has forced this publisher to mute audio.
|
static class |
PublisherKit.PublisherAudioStats
Defines audio statistics for a publisher.
|
static class |
PublisherKit.PublisherKitVideoType
Defines values for the
setPublisherVideoType(PublisherKitVideoType type) method. |
static interface |
PublisherKit.PublisherListener
Monitors when a publisher starts and stops streaming to the session.
|
static class |
PublisherKit.PublisherRtcStats
Represents RTC statistics for a media stream published by the publisher.
|
static interface |
PublisherKit.PublisherRtcStatsReportListener
Defines the listener object for getting publisher RTC stats reports.
|
static class |
PublisherKit.PublisherVideoStats
Defines video statistics for a publisher.
|
static interface |
PublisherKit.VideoStatsListener
Defines the listener object for getting publisher video statistcs.
|
Modifier and Type | Field and Description |
---|---|
protected PublisherKit.AudioLevelListener |
audioLevelListener |
protected PublisherKit.AudioStatsListener |
audioStatsListener |
protected BaseVideoCapturer |
capturer |
protected android.content.Context |
context |
protected android.os.Handler |
handler |
protected PublisherKit.MuteListener |
muteListener |
protected PublisherKit.PublisherListener |
publisherListener |
protected BaseVideoRenderer |
renderer |
protected PublisherKit.PublisherRtcStatsReportListener |
rtcStatsReportListener |
protected PublisherKit.VideoStatsListener |
videoStatsListener |
Modifier | Constructor and Description |
---|---|
|
PublisherKit(android.content.Context context)
Deprecated.
|
|
PublisherKit(android.content.Context context,
java.lang.String name)
Deprecated.
|
|
PublisherKit(android.content.Context context,
java.lang.String name,
boolean audioTrack,
boolean videoTrack)
Deprecated.
|
protected |
PublisherKit(android.content.Context context,
java.lang.String name,
boolean audioTrack,
boolean videoTrack,
BaseVideoCapturer capturer,
BaseVideoRenderer renderer)
Deprecated.
|
protected |
PublisherKit(android.content.Context context,
java.lang.String name,
boolean audioTrack,
int maxAudioBitRate,
boolean videoTrack,
BaseVideoCapturer capturer,
BaseVideoRenderer renderer,
boolean enableOpusDtx,
boolean scalableScreenshare)
Creates a new PublisherKit object.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Deprecated.
|
protected void |
finalize()
Called by the garbage collector when it determines that there are no more
references to the PublisherKit object.
|
boolean |
getAudioFallbackEnabled()
Whether the stream uses the audio-fallback feature (
true ) or not
(false ). |
BaseVideoCapturer |
getCapturer()
Returns the video capturer used by this publisher.
|
java.lang.String |
getName()
The stream name.
|
boolean |
getPublishAudio()
Whether the Publisher is publishing audio (
true ) or not (
false ). |
PublisherKit.PublisherKitVideoType |
getPublisherVideoType()
Returns the type of video for this publisher.
|
boolean |
getPublishVideo()
Whether the Publisher is publishing video (
true ) or not (
false ). |
BaseVideoRenderer |
getRenderer()
Returns the video renderer for this publisher.
|
void |
getRtcStatsReport()
Gets the RTC stats report for the publisher.
|
Session |
getSession()
Returns the
Session bound to this Publisher instance. |
Stream |
getStream()
Returns the stream object corresponding the the Publisher's stream.
|
android.view.View |
getView()
Returns the android.view.View object that contains the Publisher video.
|
protected void |
onAudioLevelUpdated(float audioLevel)
Called periodically to report the audio level of the publisher.
|
protected void |
onError(OpentokError error)
Invoked when the publisher fails.
|
protected void |
onMuteForced()
Invoked when a moderator has forced this publisher to mute audio.
|
void |
onPause()
Do not call directly; call
Session.onPause() instead. |
void |
onRestart()
Restarts publisher resources that were previously released by calling the
onStop() method. |
void |
onResume()
Do not call directly; call
Session.onResume() instead. |
protected void |
onRtcStatsReport(PublisherKit.PublisherRtcStats[] stats)
Called when the publisher's RTC stats report is available in response to a
call to
getRtcStatsReport() . |
void |
onStop()
Releases resources tied to the publisher.
|
protected void |
onStreamCreated(Stream stream)
Invoked when the publisher's stream is created.
|
protected void |
onStreamDestroyed(Stream stream)
Invoked when the publisher's stream is destroyed.
|
void |
setAudioFallbackEnabled(boolean enabled)
Whether the stream will use the audio-fallback feature (
true ) or not
(false ). |
void |
setAudioLevelListener(PublisherKit.AudioLevelListener listener)
Binds an
PublisherKit.AudioLevelListener to this PublisherKit instance to monitor audio
level updates. |
void |
setAudioStatsListener(PublisherKit.AudioStatsListener listener)
Sets up a listener for publisher audio statistics.
|
void |
setCapturer(BaseVideoCapturer newCapturer)
Deprecated.
|
void |
setMuteListener(PublisherKit.MuteListener listener)
Sets a
PublisherKit.MuteListener object to monitor when a moderator forces
this publisher to mute audio. |
void |
setName(java.lang.String name)
Deprecated.
|
void |
setPublishAudio(boolean publishAudio)
Toggles publishing of audio on or off, based on the value passed in.
|
void |
setPublisherListener(PublisherKit.PublisherListener listener)
Binds a
PublisherKit.PublisherListener to this Publisher instance to monitor state
changes. |
void |
setPublisherVideoType(PublisherKit.PublisherKitVideoType type)
Specifies the type of video for this stream.
|
void |
setPublishVideo(boolean publishVideo)
Toggles publishing of video on or off, based on the value passed in.
|
void |
setRenderer(BaseVideoRenderer renderer)
Deprecated.
|
void |
setRtcStatsReportListener(PublisherKit.PublisherRtcStatsReportListener listener)
Sets the RTC stats report listener the subscriber.
|
void |
setStyle(java.lang.String key,
java.lang.String value)
Sets a style for the video renderer used by this publisher.
|
void |
setVideoStatsListener(PublisherKit.VideoStatsListener listener)
Sets up a listener for publisher video statistics.
|
void |
update(java.util.Observable o,
java.lang.Object arg)
This method is called whenever the observed object is changed.
|
protected android.os.Handler handler
protected PublisherKit.PublisherListener publisherListener
protected PublisherKit.AudioLevelListener audioLevelListener
protected PublisherKit.VideoStatsListener videoStatsListener
protected PublisherKit.AudioStatsListener audioStatsListener
protected PublisherKit.MuteListener muteListener
protected PublisherKit.PublisherRtcStatsReportListener rtcStatsReportListener
protected android.content.Context context
protected BaseVideoRenderer renderer
protected BaseVideoCapturer capturer
@Deprecated protected PublisherKit(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer)
PublisherKit
class, 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 PublisherKit
object each time you
want to publish a new stream.
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.videoTrack
- Whether to include a video track in the published stream.renderer
- The video capturer for the publisher.renderer
- The video renderer for the publisher.setPublisherListener(PublisherKit.PublisherListener listener)
protected PublisherKit(android.content.Context context, java.lang.String name, boolean audioTrack, int maxAudioBitRate, boolean videoTrack, BaseVideoCapturer capturer, BaseVideoRenderer renderer, boolean enableOpusDtx, boolean scalableScreenshare)
PublisherKit
class,
you can call this constructor from the child class.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.scalableScreenshare
- Whether to allow use of scalable video for a publisher that has the videoType
set to PublisherKitVideoTypeScreen (true) or not (false, the default).@Deprecated public PublisherKit(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack)
PublisherKit.Builder
class 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.
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.@Deprecated public PublisherKit(android.content.Context context)
PublisherKit.Builder
class 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.
context
- The android.content.Context for the Publisher.setPublisherListener(PublisherKit.PublisherListener listener)
@Deprecated public PublisherKit(android.content.Context context, java.lang.String name)
PublisherKit.Builder
class 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.
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).setPublisherListener(PublisherKit.PublisherListener listener)
public void onPause()
Session.onPause()
instead.public void onResume()
Session.onResume()
instead.@Deprecated public void destroy()
public void setPublishVideo(boolean publishVideo)
publishVideo
- Whether to publish video (true
) or not (
false
).public void setPublishAudio(boolean publishAudio)
publishAudio
- Whether to publish audio (true
) or not (
false
).@Deprecated public void setName(java.lang.String name)
PublisherKit.PublisherListener.onStreamCreated(PublisherKit publisher, Stream stream)
method is called. Setting the property after the
PublisherKit.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).
public void setPublisherVideoType(PublisherKit.PublisherKitVideoType type)
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 the setAudioFallbackEnabled(boolean enabled)
method and pass in
false
before calling the
Session.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.public java.lang.String getName()
public boolean getPublishVideo()
true
) or not (
false
).public boolean getPublishAudio()
true
) or not (
false
).public Session getSession()
Session
bound to this Publisher instance.Session
bound to this Publisher instance.Session.publish(com.opentok.android.PublisherKit)
public Stream getStream()
public PublisherKit.PublisherKitVideoType getPublisherVideoType()
public void setPublisherListener(PublisherKit.PublisherListener listener)
PublisherKit.PublisherListener
to this Publisher instance to monitor state
changes.listener
- The PublisherKit.PublisherListener
that will monitor this instance, or null
to disconnect a listener.public void setAudioLevelListener(PublisherKit.AudioLevelListener listener)
PublisherKit.AudioLevelListener
to this PublisherKit instance to monitor audio
level updates.listener
- The PublisherKit.AudioLevelListener
that will monitor this instance. Set
this to null to disconnect a listener and stop monitoring audio levels.public void setRtcStatsReportListener(PublisherKit.PublisherRtcStatsReportListener listener)
getRtcStatsReport()
.listener
- The PublisherKit.PublisherRtcStatsReportListener
object.public void setStyle(java.lang.String key, java.lang.String value)
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 is
BaseVideoRenderer.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.
key
- The style to set.value
- The value you are setting the style to.@Deprecated public void setRenderer(BaseVideoRenderer renderer)
This method is deprecated. Instead, call
the PublisherKit.Builder.renderer(BaseVideoRenderer renderer)
method when
using the Builder to create the PublisherKit instance.
public BaseVideoRenderer getRenderer()
public BaseVideoCapturer getCapturer()
@Deprecated public void setCapturer(BaseVideoCapturer newCapturer)
This method is deprecated. Instead, call the
PublisherKit.Builder.capturer(BaseVideoCapturer capturer)
method when using
the builder to create the PublisherKit instance.
public android.view.View getView()
public void setVideoStatsListener(PublisherKit.VideoStatsListener listener)
PublisherKit.VideoStatsListener.onVideoStats(PublisherKit publisher,
PublisherKit.PublisherVideoStats[] stats)
method. This method is called periodically to report
the following:
public void setAudioStatsListener(PublisherKit.AudioStatsListener listener)
PublisherKit.AudioStatsListener.onAudioStats(PublisherKit publisher,
PublisherKit.PublisherAudioStats[] stats)
method. This method is called periodically to report
the following:
public void setMuteListener(PublisherKit.MuteListener listener)
PublisherKit.MuteListener
object to monitor when a moderator forces
this publisher to mute audio.listener
- The PublisherKit.MuteListener
instance.public void setAudioFallbackEnabled(boolean enabled)
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 in false
)
before calling the Session.publish(com.opentok.android.PublisherKit)
method.
public boolean getAudioFallbackEnabled()
true
) or not
(false
).setAudioFallbackEnabled(boolean enabled)
public void getRtcStatsReport()
setRtcStatsReportListener(PublisherKit.PublisherRtcStatsReportListener listener)
method, and then implement the
PublisherKit.PublisherRtcStatsReportListener.onRtcStatsReport(PublisherKit publisher, PublisherKit.PublisherRtcStats[] stats)
method prior to calling this method. When the stats are available, the implementation
of the PublisherKit.PublisherRtcStatsReportListener.onRtcStatsReport(PublisherKit publisher, PublisherKit.PublisherRtcStats[] stats)
method is called.
Also see setAudioStatsListener(PublisherKit.AudioStatsListener listener)
,
setVideoStatsListener(PublisherKit.VideoStatsListener listener)
, and
SubscriberKit.getRtcStatsReport()
.
protected void onRtcStatsReport(PublisherKit.PublisherRtcStats[] stats)
getRtcStatsReport()
.
If you extend the PublisherKit class, you can override this method instead of implementing the onRtcStatsReport() method of the PublisherKit.PublisherRtcStatsReportListener interface.
PublisherRtcStatsReportListener#onRtcStatsReport(PublisherKit publisher, PublisherRtcStats[] stats)
protected void onStreamCreated(Stream stream)
If you extend the PublisherKit class, you can override this method instead of the
onStreamCreated()
method of the PublisherKit.PublisherListener
interface.
stream
- The stream that that is created.protected void onStreamDestroyed(Stream stream)
If you extend the PublisherKit class, you can override this method instead of the
onStreamDestroyed()
method of the PublisherKit.PublisherListener
interface.
stream
- The stream that that is destroyed.protected void onError(OpentokError error)
If you extend the PublisherKit class, you can override this method instead of the
onError()
method of the PublisherKit.PublisherListener
interface.
error
- The error that invoked this callback.protected void onAudioLevelUpdated(float audioLevel)
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).protected void onMuteForced()
If you extend the PublisherKit class, you can override this method instead of the
onMuteForced()
method of the PublisherKit.MuteListener
interface.
public void update(java.util.Observable o, java.lang.Object arg)
update
in interface java.util.Observer
o
- The observable object.arg
- An argument passed to the notifyObservers method.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void onStop()
onRestart()
method.public void onRestart()
onStop()
method.