public class PublisherKit
extends java.lang.Object
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 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.
|
Modifier and Type | Field and Description |
---|---|
protected PublisherKit.AudioLevelListener |
audioLevelListener |
protected BaseVideoCapturer |
capturer |
protected android.content.Context |
context |
protected PublisherKit.PublisherListener |
publisherListener |
protected BaseVideoRenderer |
renderer |
protected Session |
session |
Constructor and Description |
---|
PublisherKit(android.content.Context context)
Creates a new PublisherKit instance.
|
PublisherKit(android.content.Context context,
java.lang.String name)
Creates a new PublisherKit instance.
|
PublisherKit(android.content.Context context,
java.lang.String name,
boolean audioTrack,
boolean videoTrack)
Creates a new PublisherKit instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
attachToSession(Session session) |
void |
destroy()
Releases this object, including all hardware and UI resources bound to
it.
|
protected void |
detachFromSession(Session session) |
protected void |
finalize() |
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.
|
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 int |
initCapturerRendererNative(BaseVideoCapturer capturer,
BaseVideoRenderer renderer) |
protected void |
onError(OpentokError error)
Invoked when the publisher fails.
|
void |
onPause() |
void |
onResume() |
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 |
setCapturer(BaseVideoCapturer capturer)
Deprecated.
|
void |
setName(java.lang.String name)
Set the name for this stream.
|
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)
Sets the video renderer for this publisher.
|
void |
setStyle(java.lang.String key,
java.lang.String value)
Sets a style for the video renderer used by this publisher.
|
protected PublisherKit.PublisherListener publisherListener
protected PublisherKit.AudioLevelListener audioLevelListener
protected Session session
protected android.content.Context context
protected BaseVideoRenderer renderer
protected BaseVideoCapturer capturer
public PublisherKit(android.content.Context context)
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.
You cannot reuse a publisher after you have called the destroy()
method.
context
- The android.content.Context for the Publisher.setPublisherListener(PublisherKit.PublisherListener listener)
public PublisherKit(android.content.Context context, java.lang.String name)
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.
You cannot reuse a publisher after you have called the destroy()
method.
context
- The android.content.Context for the Publisher.name
- The name of the publisher video. The Stream.name
property for a stream
published by this publisher will be set to this value (on all clients).setPublisherListener(PublisherKit.PublisherListener listener)
public PublisherKit(android.content.Context context, java.lang.String name, boolean audioTrack, boolean videoTrack)
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.
You cannot reuse a publisher after you have called the destroy()
method.
context
- The android.content.Context for the Publisher.name
- The name of the publisher video. The Stream.name
property for a stream
published by this publisher will be set to 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.protected void attachToSession(Session session)
protected void detachFromSession(Session session)
public void onPause()
public void onResume()
public void destroy()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
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
).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 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.public void setRenderer(BaseVideoRenderer renderer)
renderer
- The video renderer for this publisher to use.public BaseVideoRenderer getRenderer()
public BaseVideoCapturer getCapturer()
@Deprecated public void setCapturer(BaseVideoCapturer capturer)
This method is deprecated. Instead, use the capturer
property when creating a custom PublisherKit implementation. Or use the new
Publisher.Publisher(Context context, String name, BaseVideoCapturer capturer)
constructor.
capturer
- The video capturer for this publisher to use.
This call should be called before publishing or starting a previewprotected int initCapturerRendererNative(BaseVideoCapturer capturer, BaseVideoRenderer renderer)
public android.view.View getView()
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.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)