public class StreamManager extends Object
StreamManager
is used to manage a rtmp client for Straas.
To construct a StreamManager
, you have to call initialize(Identity)
or initialize(Identity, Bundle)
to get your result. These methods will check your developer credential, if it passed, you will get a
StreamManager
. Then, you can use methods in StreamManager
to start live streaming.
Modifier and Type | Class and Description |
---|---|
static interface |
StreamManager.StreamState
Show state of StreamManager.
|
Modifier and Type | Field and Description |
---|---|
static int |
STATE_CONNECTING
The state
StreamManager is trying to create a live event or establish rtmp connection. |
static int |
STATE_DISCONNECTING
The state
StreamManager is trying to disconnect. |
static int |
STATE_IDLE
The initial state or the state after
destroy() |
static int |
STATE_PREPARED
The state after
prepare(io.straas.android.sdk.streaming.StreamConfig, android.view.TextureView) finishes successfully. |
static int |
STATE_PREPARING
The state
StreamManager is executing StreamManager . |
static int |
STATE_STREAMING
The state
StreamManager is streaming. |
Modifier and Type | Method and Description |
---|---|
void |
addAllEventListener(EventListener... listeners) |
boolean |
addEventListener(EventListener listener) |
com.google.android.gms.tasks.Task<Void> |
cleanLiveEvent(String liveId)
Deprecated.
Use
endLiveEvent(String) instead. |
com.google.android.gms.tasks.Task<String> |
createLiveEvent(LiveEventConfig config)
Create a live event.
|
com.google.android.gms.tasks.Task<Void> |
destroy()
Destroy
StreamManager . |
com.google.android.gms.tasks.Task<Void> |
endLiveEvent(String liveId)
Sets a live event state to ended.
|
int |
getStreamState()
Gets current StreamManager state.
|
StreamStatsReport |
getStreamStatsReport()
Gets the instant snapshot for StreamStatsReport.
|
static com.google.android.gms.tasks.Task<StreamManager> |
initialize(Identity identity)
Constructs a
StreamManager if you are a authorized developer. |
static void |
initialize(Identity identity,
Bundle bundle)
Constructs a
StreamManager and return it to your class implementing ScreencastSession via the callback
ScreencastSession.onStreamManagerInitComplete(Task<>) if you are a authorized developer. |
boolean |
isAudioEnabled()
Returns the enabled status of audio.
|
com.google.android.gms.tasks.Task<Void> |
prepare(ScreencastStreamConfig config)
Checks if
ScreencastStreamConfig is valid, then initializes microphone and codec. |
com.google.android.gms.tasks.Task<CameraController> |
prepare(StreamConfig config,
TextureView preview)
Initializes camera, codec, microphone, you will be able to preview the live video after
prepare success.
|
void |
removeAllEventListener()
Remove all event listener, no one could receive future event.
|
boolean |
removeEventListener(EventListener listener) |
void |
setAudioEnabled(boolean enabled)
Sets the enabled status of audio.
|
boolean |
setFilter(BaseImageFilter filter)
Sets filter for video.
|
void |
setStreamStatsReportUpdatePeriod(int periodMs)
Sets the update period in millis for stream statistics report.
|
com.google.android.gms.tasks.Task<String> |
startStreaming(String liveId)
Deprecated.
Use
startStreamingWithLiveId(java.lang.String) instead. |
com.google.android.gms.tasks.Task<Void> |
startStreamingWithLiveId(String liveId)
Starts to stream.
|
com.google.android.gms.tasks.Task<Void> |
startStreamingWithStreamKey(String streamKey)
Starts to stream.
|
com.google.android.gms.tasks.Task<Void> |
stopStreaming()
Stops the operation doing in
startStreamingWithLiveId(String) or startStreamingWithStreamKey(String) ,
that is connecting and streaming. |
public static final int STATE_IDLE
destroy()
public static final int STATE_PREPARING
StreamManager
is executing StreamManager
.public static final int STATE_PREPARED
prepare(io.straas.android.sdk.streaming.StreamConfig, android.view.TextureView)
finishes successfully. You can start streaming
by invoking startStreamingWithLiveId(String)
or startStreamingWithStreamKey(String)
in this state.public static final int STATE_CONNECTING
StreamManager
is trying to create a live event or establish rtmp connection.public static final int STATE_STREAMING
StreamManager
is streaming.public static final int STATE_DISCONNECTING
StreamManager
is trying to disconnect.public static com.google.android.gms.tasks.Task<StreamManager> initialize(Identity identity)
StreamManager
if you are a authorized developer.identity
- Any task of the StreamManager
you get will be executed by this Identity
.StreamManager
by the Task
if task succeeded.public static void initialize(Identity identity, Bundle bundle)
StreamManager
and return it to your class implementing ScreencastSession
via the callback
ScreencastSession.onStreamManagerInitComplete(Task<>)
if you are a authorized developer.
Also starting a foreground screencast Service
to run ScreencastSession
.identity
- Any task of the StreamManager
you get will be executed by this Identity
.bundle
- provides any information for screencast setup or other purposes, this will be delivered to
ScreencastSession.onSessionCreate(Context, SessionListener, Bundle)
Service.startForeground(int, Notification)
,
Settings.canDrawOverlays(Context)
public com.google.android.gms.tasks.Task<CameraController> prepare(StreamConfig config, TextureView preview)
STATE_IDLE
or STATE_PREPARED
.config
- provides information of stream, see StreamConfig
preview
- TextureView to preview videoCameraController
by the Task
if task succeeded.public com.google.android.gms.tasks.Task<Void> prepare(ScreencastStreamConfig config)
ScreencastStreamConfig
is valid, then initializes microphone and codec.
This method should only be called when the StreamManager status is STATE_IDLE
or STATE_PREPARED
.config
- provides streaming information for screencast, see ScreencastStreamConfig
Task
.public boolean setFilter(@Nullable BaseImageFilter filter)
getStreamState()
>= STATE_PREPARED
filter
- see BaseImageFilter
. Set this to null to disable filter.public void setAudioEnabled(boolean enabled)
getStreamState()
>= STATE_PREPARED
enabled
- True if the audio is enabled, false otherwise.isAudioEnabled()
public boolean isAudioEnabled()
getStreamState()
>= STATE_PREPARED
setAudioEnabled(boolean)
public com.google.android.gms.tasks.Task<String> createLiveEvent(@NonNull LiveEventConfig config)
StreamException.LiveCountLimitException
from the returned task if there is a not-ended
live event already. If so, you can use startStreamingWithLiveId(String)
or
endLiveEvent(String)
to handle the live event getting by
StreamException.LiveCountLimitException.getLiveId()
.
This method should only be called when the getStreamState()
<= STATE_PREPARED
Note: this method is only available for authorized users. That means you shouldn't call
this when the current member is Identity.GUEST
.config
- configuration of live eventTask
if task succeeded.@Deprecated public com.google.android.gms.tasks.Task<String> startStreaming(@NonNull String liveId)
startStreamingWithLiveId(java.lang.String)
instead.STATE_PREPARED
.
Note: this method is only available for authorized users. That means you shouldn't call
this when the current member is Identity.GUEST
.liveId
- live event id, you can create this by createLiveEvent(LiveEventConfig)
Task
if task succeeded.public com.google.android.gms.tasks.Task<Void> startStreamingWithLiveId(@NonNull String liveId)
STATE_PREPARED
.
Note: this method is only available for authorized users. That means you shouldn't call
this when the current member is Identity.GUEST
.liveId
- live event id, you can create this by createLiveEvent(LiveEventConfig)
Task
if task succeeded.public com.google.android.gms.tasks.Task<Void> startStreamingWithStreamKey(@NonNull String streamKey)
Identity.GUEST
.
This method should only be called when the StreamManager status is STATE_PREPARED
.streamKey
- stream keyTask
.public boolean addEventListener(EventListener listener)
listener
- Listens result of connection and other events.
See EventListener
.public void addAllEventListener(EventListener... listeners)
listeners
- Listens result of connection and other events.
See EventListener
.public boolean removeEventListener(EventListener listener)
listener
- Remove listener which doesn't want to receive future event.
See EventListener
.public void removeAllEventListener()
EventListener
.public com.google.android.gms.tasks.Task<Void> stopStreaming()
startStreamingWithLiveId(String)
or startStreamingWithStreamKey(String)
,
that is connecting and streaming. This method won't set the current live event to ENDED, you
can use endLiveEvent(String)
if needed.
This method should only be called when the StreamManager status is STATE_CONNECTING
or STATE_STREAMING
.Task
.public com.google.android.gms.tasks.Task<Void> destroy()
StreamManager
. This method will do operation in stopStreaming()
and
release resources generated at prepare(io.straas.android.sdk.streaming.StreamConfig, android.view.TextureView)
. This method won't set current the live event
to ENDED, you can use endLiveEvent(String)
if needed.
This method shouldn't be called when the StreamManager status is STATE_IDLE
.Task
.@Deprecated public com.google.android.gms.tasks.Task<Void> cleanLiveEvent(@NonNull String liveId)
endLiveEvent(String)
instead.Identity.GUEST
.liveId
- live event idTask
.public com.google.android.gms.tasks.Task<Void> endLiveEvent(@NonNull String liveId)
Identity.GUEST
.liveId
- live event idTask
.public int getStreamState()
StreamManager.StreamState
@Nullable public StreamStatsReport getStreamStatsReport()
The returned stream statistics report instance won't update automatically, you have to call this method every time you want to get the instant report.
Alternatively, you could use addEventListener(io.straas.android.sdk.streaming.interfaces.EventListener)
to subscribe event
EventListener.onStreamStatsReportUpdate(StreamStatsReport)
to receive the update of
stream statistics report periodically.
You can specify the update period of stream statistics report by
setStreamStatsReportUpdatePeriod(int)
. Default value is one second.
This method should only be called when the StreamManager status is STATE_STREAMING
or STATE_DISCONNECTING
.
StreamStatsReport
public void setStreamStatsReportUpdatePeriod(int periodMs)
periodMs
- the update period in millisecond for
EventListener.onStreamStatsReportUpdate(StreamStatsReport)
.