Android SDK Version Comparison - PhenixRTS Docs

Android SDK Version Comparison

This page provides information about APIs and features that are no longer supported by the current Android SDK release but may be in use by developers that are using prior versions of the SDK. Links to the GA version of the documentation are provided when possible.

A copy of the deprecated documentation is shown with a blue background for easier identification when comparing to current documentation.

All deprecated documentation is watermarked DEPRECATED to allow easy identification.

v2022.0.3 and Earlier#Copied URL

PCast™ Express#Copied URL

Newer versions of PCast™ Express do not support certain arguments in

Using these arguments with the newer SDK will result in a failure such as unrecognised option.

Some APIs, such as Publishing Remote Media (Ingest), are not supported by newer versions of the SDK.

In addition, token arguments are required when using the newer SDK (e.g., withStreamToken or withAuthenticationToken), and not including tokens will result in a failure such as bad-request.

Initializing PCast™ Express#Copied URL

Current version: Initializing

Deprecated version:

Copy

import android.content.Context;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.environment.android.AndroidContext;
import com.phenixrts.express.ChannelExpressFactory;
import com.phenixrts.express.ChannelExpressOptions;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PCastExpressOptions;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.express.RoomExpressOptions;

// IMPORTANT: Before accessing any of the static factories, make sure the context is passed to Phenix:
final Context context = ...;  // e.g. Activity.getApplication();
AndroidContext.setContext(context);

final PCastExpressOptions pcastExpressOptions =
    PCastExpressFactory.createPCastExpressOptionsBuilder()
        .withStreamToken("DIGEST:eyJhc...")
        .withUnrecoverableErrorCallback((status, description) -> {
          // Best option is to try rebuilding the ChannelExpress instance and/or quit
          // your app
        })
        .buildPCastExpressOptions();

final RoomExpressOptions roomExpressOptions =
    RoomExpressFactory.createRoomExpressOptionsBuilder()
        .withPCastExpressOptions(pcastExpressOptions)
        .buildRoomExpressOptions();

final ChannelExpressOptions channelExpressOptions =
    ChannelExpressFactory.createChannelExpressOptionsBuilder()
        .withRoomExpressOptions(roomExpressOptions)
        .buildChannelExpressOptions();

final ChannelExpress channelExpress = ChannelExpressFactory.createChannelExpress(channelExpressOptions);

PCastExpressOptionsBuilder#Copied URL

Name Type Default Description
withBackendUri (required) String Url to your backend. We send requests here to authenticate and get streaming tokens.
withAuthenticationData (optional) String Your authentication data for the user. On every request, this will be sent to your backend through a HTTP POST request and all its attributes would be accessible on the request body. Needs to be valid JSON.
withAuthenticationToken (optional) String The authentication token generated using the Phenix EdgeAuth library.
withUnrecoverableErrorCallback (optional) PCastExpressOptions.UnrecoverableErrorCallback Function to be called when authentication fails or a failure occurs that is unrecoverable.
withPCastUri (optional) String Allows overriding default PCast™ URI.
withPCastInitializationOptions (optional) PCastInitializeOptions Use custom options when initializing PCast™.
withAuthenticationRouteOverride (optional) String auth Allows override of default route for authentication tokens
withStreamRouteOverride (optional) String stream Allows override of default route for stream tokens
buildPCastExpressOptions none Builds the PCastExpressOptions

Publishing Local Media#Copied URL

Current version: Publishing Local Media

Deprecated version:

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ExpressPublisher;
import com.phenixrts.express.PCastExpress;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PublishOptions;
import com.phenixrts.pcast.AudioEchoCancelationMode;
import com.phenixrts.pcast.DeviceCapability;
import com.phenixrts.pcast.DeviceConstraint;
import com.phenixrts.pcast.FacingMode;
import com.phenixrts.pcast.Renderer;
import com.phenixrts.pcast.UserMediaOptions;
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;
import java.util.Arrays;

final PCastExpress pcastExpress = ...;  // previously obtained

final UserMediaOptions userMediaConstraints = new UserMediaOptions();

userMediaConstraints.getVideoOptions().enabled = true;
userMediaConstraints.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FACING_MODE,
    Arrays.asList(new DeviceConstraint(FacingMode.USER)));

userMediaConstraints.getAudioOptions().enabled = true;
userMediaConstraints.getAudioOptions().capabilityConstraints.put(
    DeviceCapability.AUDIO_ECHO_CANCELATION_MODE,
    Arrays.asList(new DeviceConstraint(AudioEchoCancelationMode.ON)));

final PublishOptions publishOptions = PCastExpressFactory.createPublishOptionsBuilder()
    .withCapabilities(new String[] {"real-time"})
    .withMediaConstraints(userMediaConstraints)
    .buildPublishOptions();

pcastExpress.publish(publishOptions, (RequestStatus status, ExpressPublisher publisher) -> {
  if (status == RequestStatus.OK) {
    // Do something with publisher
  } else {
    // Handle error
  }
});

// Create a publisher with an automatically started preview renderer
final SurfaceView view = ...;  // previously obtained
final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

final PublishOptions publishOptionsWithPreview = PCastExpressFactory.createPublishOptionsBuilder()
    .withCapabilities(new String[] {"real-time"})
    .withMediaConstraints(userMediaConstraints)
    .withPreviewRenderer(renderSurface)
    .buildPublishOptions();

pcastExpress.publish(
    publishOptions, (RequestStatus status, ExpressPublisher publisher, Renderer preview) -> {
  if (status == RequestStatus.OK) {
    // Do something with publisher and preview renderer
  } else {
    // Handle error
  }
});

✂ Unchanged content not shown

PublishOptionsBuilder#Copied URL

Name Type Default Description
withMediaConstraints (required) UserMediaOptions getUserMedia options Constraints to get the user media.
withUserMedia (optional) UserMediaStream alternative to withMediaConstraints - you can pass user media stream returned from getUserMedia.
withCapabilities (optional) String[] The list of all capabilities to publish with. Default is empty array.
withPreviewRenderer (optional) AndroidVideoRenderSurface Render layer on which to display local preview. If none of the withPreview... methods are called, no preview renderer will be instantiated.
withPreviewRenderer (optional) none Will trigger instantiation of preview renderer. Useful for audio only type streams that do not require a render surface.
withPreviewRendererOptions (optional) RendererOptions Options passed to preview renderer. Will trigger instantiation of preview renderer.
withMonitor (optional) MonitorOptions.SetupFailedCallback, MonitorOptions.StreamEndedCallback, MonitorOptions Options for monitoring a publisher for failure.
withConnectOptions (optional) Strings[] List of options for publishing.
withTags (optional) Strings[] Tags for the stream.
withStreamToken (optional) String The publish token generated using the Phenix EdgeAuth library.
buildPublishOptions none Builds the PublishOptions

Publishing Remote Media (Ingest)#Copied URL

Current version: This API is not supported by newer versions of the Android SDK. To publish remote media, please use the REST API for publishing a stream from a URI.

Deprecated version:

Publish from remote sources into the Phenix platform. This enables us to distribute your source media using the Phenix platform. After publishing users may subscribe to the stream using either pcast subscribe or express subscribe.

Copy

import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ExpressPublisher;
import com.phenixrts.express.PCastExpress;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PublishRemoteOptions;

final PCastExpress pcastExpress = ...;  // previously obtained

final PublishRemoteOptions publishRemoteOptions = PCastExpressFactory.createPublishRemoteOptionsBuilder()
    .withStreamUri("http://mycdn.example.com/mystream.mp4")
    .withCapabilities(new String[] {})
    .buildPublishRemoteOptions();

pcastExpress.publishRemote(publishRemoteOptions, (RequestStatus status, ExpressPublisher publisher) -> {
  if (status == RequestStatus.OK) {
    // Do something with publisher
  } else {
    // Handle error
  }
});

Publish Remote Options Parameters#Copied URL

Name Type Description
options (required) PublishRemoteOptions Publish Remote options
callback (required) PCastExpress.PublishCallback Callback for error/success handling

PublishRemoteOptionsBuilder#Copied URL

Name Type Default Description
withCapabilities (required) String[] The list of all capabilities to publish with.
withStreamUri (required) String Link to remote media (mp4, rtmp, etc.)
withStreamToken (optional) String The publish token generated using the Phenix EdgeAuth library.
withConnectOptions (optional) Strings[] List of options for publishing from a remote source.
withTags (optional) Strings[] Tags for the stream
withMaximumFrameRateConstraint (optional) double Maximum frame rate constraint.
withExactFrameRateConstraint (optional) double Exact frame rate constraint.
withPrerollSkipDuration (optional) long 500 The amount of time to skip at the beginning of the media in milliseconds.
buildPublishRemoteOptions none Builds the PublishRemoteOptions

Publish Remote Options Callback Arguments#Copied URL

Name Type Description
status RequestStatus The status of the operation. See Publish Callback Status Codes
publisher ExpressPublisher Phenix publisher object

Subscribing to Published Media#Copied URL

Current version: Subscribing to Published Media

Deprecated version:

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ExpressSubscriber;
import com.phenixrts.express.PCastExpress;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.SubscribeOptions;
import com.phenixrts.pcast.Renderer;
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;

final PCastExpress pcastExpress = ...;  // previously obtained
final SurfaceView view = ...;  // previously obtained

final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

final SubscribeOptions subscribeOptions = PCastExpressFactory.createSubscribeOptionsBuilder()
    .withStreamId("us-west#us-west1-b.zzzzzzzz.20000000.xxxxxxxx")
    .withCapabilities(new String[] {"streaming"})
    .withRenderer(renderSurface)
    .buildSubscribeOptions();

pcastExpress.subscribe(
    subscribeOptions,
    (RequestStatus status, ExpressSubscriber subscriber, Renderer renderer) -> {
  if (status == RequestStatus.OK) {
    // Do something with subscriber

if (renderer != null) {
      // Returned if `withRenderer...` option was enabled - Do something with renderer
    }
  } else {
    // Handle error
  }
});

✂ Unchanged content not shown

Subscribe Options#Copied URL

Name Type Default Description
withStreamId (required) String The stream ID of the published stream
withCapabilities (required) String[] The list of all capabilities to subscribe with.
withStreamToken (optional) String The subscribe token generated using the Phenix EdgeAuth library.
withRenderer (optional) AndroidVideoRenderSurface Render layer on which to display stream. If none of the withRenderer... methods are called, no renderer will be instantiated.
withRenderer (optional) none Will trigger instantiation of renderer. Useful for audio only type streams that do not require a render surface.
withRendererOptions (optional) RendererOptions Options passed to renderer. Will trigger instantiation of renderer.
withMonitor (optional) MonitorOptions.SetupFailedCallback, MonitorOptions.StreamEndedCallback, MonitorOptions Options for monitoring a subscriber for failure.
withConnectOptions (optional) String[] List of options for subscribing.
withTags (optional) NSString[] Tags for the stream
buildSubscribeOptions none Builds the SubscribeOptions

ExpressSubscriber#Copied URL

Shares most methods with regular MediaStream returned by PCast™, see Subscribe to a Stream.

Name Signature Returns Description
createRenderer () Renderer Creates a new renderer. This should only be called if none of the withRenderer... builder methods were invoked.
createRenderer (RendererOptions) Renderer Creates a new renderer with RendererOptions. This should only be called if none of the withRenderer... builder methods were invoked.
getAudioTracks () MediaStreamTrack[] Returns all associated audio tracks of this stream
getVideoTracks () MediaStreamTrack[] Returns all associated video tracks of this stream
getTracks () MediaStreamTrack[] Returns all associated tracks of this stream
stop () void Stops subscription. This will trigger the stream ended event.
disableAudio () void Mutes audio.
enableVideo () void Unmutes video.
disableVideo () void Mutes video (black frames).

Monitor#Copied URL

Note: On Android, the monitor options are currently ignored, but the callbacks for stream setup and stream ended will be triggered.

Monitor callbacks and options can be passed to subscribe and publish options builders. The first callback gets invoked only when we internally fail to setup a stream. The second callback gets invoked whenever a stream ends, whether it is due to failure or not. The retry OptionalAction allows you to retry publishing or subscribing the failed stream. You must test first whether there is a retry action present by calling isPresent as it may not be possible to retry the stream (example: a stream that ended normally cannot be retried). You should call dismiss on the retry action to dismiss it, close has the same effect. You also may defer invoking the retry action.

Example Monitor for subscribing

Copy

import com.phenixrts.common.OptionalAction;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ExpressSubscriber;
import com.phenixrts.express.MonitorOptions;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.SubscribeOptions;
import com.phenixrts.pcast.StreamEndedReason;

final MonitorOptions monitorOptions = PCastExpressFactory.createMonitorOptionsBuilder()
    .buildMonitorOptions();

final SubscribeOptions subscribeOptions = PCastExpressFactory.createSubscribeOptionsBuilder()
    .withStreamId("us-west#us-west1-b.zzzzzzzz.20000000.xxxxxxxx")
    .withStreamToken("DIGEST:eyJhc...")
    .withMonitor(
        (RequestStatus status, OptionalAction retry) -> {
          if (retry.isPresent()) {
            if (shouldRetry()) {  // <- Your logic goes here
              retry.perform();
            } else {
              retry.dismiss();
            }
          }
        },
        (StreamEndedReason reason, String description, OptionalAction retry) -> {
          if (retry.isPresent()) {
            if (reason == StreamEndedReason.FAILED) {  // <- Just an example
              retry.perform();
            } else {
              retry.dismiss();
            }
          }
        },
        monitorOptions)
    .buildSubscribeOptions();

OptionalAction#Copied URL

Name Signature Returns Description
perform () void Performs the action. This will cause a failure if isPresent is false.
dismiss () void Dismisses the action (if any). Can be called multiple times, will result in isPresent to return false. Invoking close has same effect.
isPresent () boolean Indicates whether an action can be performed.

MonitorSetupFailedCallback Callback Arguments#Copied URL

Name Type Description
status RequestStatus The status of the operation.
retry OptionalAction Optionally allow retrying the failed stream.

MonitorStreamEndedCallback Callback Arguments#Copied URL

Name Type Description
reason StreamEndedReason Reason for stream ended.
description String Optional additional ended reason description. Carries custom message.
retry OptionalAction Optionally allow retrying the failed stream. For normally ended streams isPresent will always return false.

Channel Express#Copied URL

Newer versions of Channel Express do not support certain arguments in

Using these arguments with the newer SDK will result in a failure such as unrecognised option. These arguments are documented in either the PCast™ Express or Room Express sections of this page.

View a Channel#Copied URL

Current version: View a Channel

Join a channel and automatically view the most recent content published to that channel.

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ChannelExpress;
import com.phenixrts.express.ChannelExpressFactory;
import com.phenixrts.express.JoinChannelOptions;
import com.phenixrts.express.JoinRoomOptions;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.pcast.RendererOptions;
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;
import com.phenixrts.room.RoomService;

final ChannelExpress channelExpress = ...;  // previously obtained
final SurfaceView view = ...;  // previously obtained

final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

// Just an example (you can omit renderer options if defaults are ok)
final RendererOptions rendererOptions = new RendererOptions();
rendererOptions.aspectRatioMode = AspectRatioMode.LETTERBOX;

final JoinRoomOptions joinRoomOptions = RoomExpressFactory.createJoinRoomOptionsBuilder()
    .withRoomId("us-central#xxxxx#channel")
    .withStreamToken("DIGEST:eyJhc...")
    .buildJoinRoomOptions();
final JoinChannelOptions joinChannelOptions =
    ChannelExpressFactory.createJoinChannelOptionsBuilder()
        .withJoinRoomOptions(joinRoomOptions)
        .withRenderer(renderSurface)
        .withRendererOptions(rendererOptions)
        .buildJoinChannelOptions();

this.channelExpress.joinChannel(
    joinChannelOptions,
    (RequestStatus status, RoomService roomService) -> {
      if (status != RequestStatus.OK) {
        // Handle room join error
        return;
      }

// Important: Store room service reference, otherwise we will leave channel again
      // as soon as this RoomService instance is garbage collected:
      OuterClass.this.currentRoomService = roomService;
    },
    (RequestStatus status, ExpressSubscriber subscriber, Renderer renderer) -> {
      switch (status) {
        case OK:
          // Successfully subscribed to a stream. No need to hold on to any references
          break;

case NO_STREAM_PLAYING:
          // No stream playing in channel, update UI accordingy
          break;

default:
          // We failed to subscribe and retry attempts must have failed
          break;
      }
    });

View Channel Parameters#Copied URL

Name Type Description
options (required) Options Options to join channel with
joinChannelCallback (required) ChannelExpress.JoinChannelCallback Function to call on success/failure of joining the channel.
subscriberCallback (required) PCastExpress.SubscribeCallback Function to call on when the most recent presenter changes.

JoinChannelOptionsBuilder#Copied URL

Name Type Default Description
withJoinRoomOptions (required) JoinRoomOptions See JoinRoomOptionsBuilder
withStreamToken (required) NSString The publish token generated using the Phenix EdgeAuth library.
withRenderer (optional) AndroidVideoRenderSurface Render layer on which to display stream. If none of the withRenderer... methods are called, no renderer will be instantiated.
withRenderer (optional) none Will trigger instantiation of renderer. Useful for audio only type streams that do not require a render surface.
withRendererOptions (optional) RendererOptions Options passed to renderer. Will trigger instantiation of renderer.
withStreamSelectionStrategy (optional) StreamSelectionStrategy StreamSelectionStrategy.MOST_RECENT Determines how member streams are selected for subscriptions.
buildJoinChannelOptions none Builds the JoinChannelOptions

Stream Selection Strategy#Copied URL

Strategy Description
StreamSelectionStrategy.MOST_RECENT Select the most recent stream. Viewing stream changes any time a stream starts or is updated in the room.
StreamSelectionStrategy.HIGH_AVAILABILITY Select streams for increased reliability and redundancy. Viewing stream will only change in the event of a failure of the prior selected stream.

Express Join Channel Callback Arguments#Copied URL

Name Type Description
status PhenixRequestStatus The status of the operation
roomService RoomService Room service object

View Channel Subscriber Callback Status Codes#Copied URL

Status Description
ok Successfully subscribed to presenter
no-stream-playing No presenter in room to subscribe to. Wait for presenter to join.
varies Subscribe to presenter failed for other reasons

Publish to a Channel#Copied URL

Current version: Publish to a Channel

Deprecated version:

Publish a local or remote media to a channel. Users that are viewing the channel will see your media.

✂ Unchanged content not shown

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ChannelExpress;
import com.phenixrts.express.ChannelExpressFactory;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PublishOptions;
import com.phenixrts.express.PublishToChannelOptions;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.pcast.DeviceCapability;
import com.phenixrts.pcast.FacingMode;
import com.phenixrts.pcast.RendererOptions;
import com.phenixrts.pcast.UserMediaOptions;
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;
import com.phenixrts.room.ChannelOptions;
import com.phenixrts.room.RoomServiceFactory;

final ChannelExpress channelExpress = ...;  // previously obtained
final SurfaceView view = ...;  // previously obtained

final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

// Using ChannelOptions means that the channel may or may not already exist.
// If the channel ID is known in advance, it is recommended to use `withChannelId` instead
// of `withChannelOptions` when assembling the `PublishToChannelOptions` below
final ChannelOptions channelOptions = RoomServiceFactory.createChannelOptionsBuilder()
    .withName("MyAwesomeChannel")
    // Not required but if it is provided we will use this as the alias instead
    // of pre-generating one for you:
    .withAlias("MyAwesomeChannelAlias")
    .buildChannelOptions();

// Example constraints. Audio and video are enabled by default
final UserMediaOptions mediaConstraints = new UserMediaOptions();
mediaConstraints.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FACING_MODE, Arrays.asList(new DeviceConstraint(FacingMode.USER)));
mediaConstraints.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FRAME_RATE, Arrays.asList(new DeviceConstraint(15)));
mediaConstraints.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.HEIGHT, Arrays.asList(new DeviceConstraint(720)));
mediaConstraints.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.WIDTH, Arrays.asList(new DeviceConstraint(1280)));

final PublishOptions publishOptions = PCastExpressFactory.createPublishOptionsBuilder()
    .withStreamToken("DIGEST:eyJhc...")
    .withMediaConstraints(mediaConstraints)
    .withPreviewRenderer(renderSurface)
    .buildPublishOptions();

final PublishToChannelOptions publishToChannelOptions =
    ChannelExpressFactory.createPublishToChannelOptionsBuilder()
        .withChannelOptions(channelOptions)
        .withPublishOptions(publishOptions)
        .buildPublishToChannelOptions();

channelExpress.publishToChannel(
    publishToChannelOptions,
    (publishStatus, roomService, publisher, previewRenderer) -> {
      if (publishStatus != RequestStatus.OK) {
        // Handle channel publish error
        return;
      }

// Important: Store publisher reference, otherwise we will stop publishing again immediately:
      currentPublisher = publisher;
    }
);

// OR (without a preview):

channelExpress.publishToChannel(
    publishToChannelOptions,
    (publishStatus, roomService, publisher) -> {
      if (publishStatus != RequestStatus.OK) {
        // Handle channel publish error
        return;
      }

// Important: Store publisher reference, otherwise we will stop publishing again immediately:
      currentPublisher = publisher;
    }
);

Publish To Channel Parameters#Copied URL

Name Type Description
options (required) Options Options to publish to channel with
publisherCallback (required) Function Function to call on success/failure of publishing to the channel

PublishToChannelOptionsBuilder#Copied URL

Name Type Default Description
withChannelOptions (required) ChannelOptions See ChannelOptionsBuilder. If omitted, then withChannelId needs to be provided.
withChannelId (required) String ID of channel to publish to. If omitted, then withChannelOptions needs to be provided.
withPublishOptions (required) PublishOptions Either provide this or remote publish options
withPublishRemoteOptions (required) RemotePublishOptions Either provide this or publish options.
withMemberRole (optional) MemberRole MemberRole.PRESENTER Role of member to join channel as (used if not already in channel).
withStreamType (optional) StreamType StreamType.PRESENTATION Type of stream to publish.
withScreenName (optional) String random unique string Screen name of self member
withViewerStreamSelectionStrategy (optional) StreamSelectionStrategy StreamSelectionStrategy.MOST_RECENT Stream selection strategy; must match the strategy channel viewers are using.
buildPublishToChannelOptions none Builds the PublishToChannelOptions

Notes:

ChannelOptionsBuilder#Copied URL

Name Type Default Description
withName (required) String Name of channel
withAlias (optional) String generated Channel Alias
withDescription (optional) String empty Channel description
buildChannelOptions none Builds the ChannelOptions

Publish To Channel Callback Arguments#Copied URL

Name Type Description
status RequestStatus The status of the operation
roomService RoomService Phenix room service
publisher ExpressPublisher Publisher object

Create a Channel (deprecated)#Copied URL

Current version: Creating a Channel is no longer supported by the Android SDK. Please use the REST API to create a Channel.

Deprecated version:

Creation of Channels from client SDKs is deprecated. Channels should be created by the backend using the REST\ API.

Copy

import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.ChannelExpress;
import com.phenixrts.room.ChannelOptions;
import com.phenixrts.room.RoomServiceFactory;

final ChannelExpress channelExpress = ...;  // previously obtained

final ChannelOptions channelOptions = RoomServiceFactory.createChannelOptionsBuilder()
    .withName("MyAwesomeChannel")
    // Not required but if it is provided we will use this as the alias instead
    // of pre-generating one for you.
    .withAlias("MyAwesomeChannelAlias")
    .buildChannelOptions();

this.channelExpress.createChannel(
    channelOptions,
    (status, channel) -> {
      if (status != RequestStatus.OK) {
        // Handle room create error
        return;
      }

// use `channel` to e.g. join
    });

Express Create Channel Parameters#Copied URL

Name Type Description
options (required) ChannelOptions Options to create channel with
callback (required) Function Function to call on success/failure of creating to the channel. See Create Channel Callback Arguments

Express Create Channel Callback Arguments#Copied URL

Name Type Description
status RequestStatus The status of the operation.
channel ImmutableRoom Immutable room object

Room Express#Copied URL

Newer versions of Room Express do not support certain arguments in

Newer versions of Room Express do not support wildcard tokens in the PhenixPublishToRoomOptionsBuilder.

Initializing Room Express#Copied URL

Current version: Initializing

Deprecated version:

Copy

import android.content.Context;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.environment.android.AndroidContext;
import com.phenixrts.express.PCastExpress;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PCastExpressOptions;
import com.phenixrts.express.RoomExpress;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.express.RoomExpressOptions;
import com.phenixrts.pcast.PCastInitializeOptions;

final PCastExpressOptions pcastExpressOptions =
    PCastExpressFactory.createPCastExpressOptionsBuilder()
        .withStreamToken("DIGEST:eyJhc...")
        .withUnrecoverableErrorCallback((RequestStatus status, String description) -> {
          // Best to restart app, or attempt to re-create PCastExpress
        })
        .buildPCastExpressOptions();

final RoomExpressOptions roomExpressOptions =
    RoomExpressFactory.createRoomExpressOptionsBuilder()
        .withPCastExpressOptions(pcastExpressOptions)
        .buildPCastExpressOptions();

final RoomExpress roomExpress = RoomExpressFactory.createRoomExpress(roomExpressOptions);

RoomExpressOptionsBuilder#Copied URL

Name Type Default Description
withPCastExpressOptions (required) PCastExpressOptions See PCastExpressOptionsBuilder
buildRoomExpressOptions none Builds the RoomExpressOptions

Join a Room#Copied URL

Current version: Join a Room

Deprecated version:

Join a room and optionally, automatically subscribe to member changes.

Copy

import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.JoinRoomOptions;
import com.phenixrts.express.RoomExpress;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.room.Member;
import com.phenixrts.room.RoomService;

final RoomExpress roomExpress = ...;  // previously obtained

final JoinRoomOptions joinRoomOptions = RoomExpressFactory.createJoinRoomOptionsBuilder()
    .withRoomId("us-central#xxxxx#channel")
    .withRoomAlias("myRoom42")
    .withCapabilities(new String[] {"streaming"})
    .buildJoinRoomOptions();

roomExpress.joinRoom(joinRoomOptions, (RequestStatus status, RoomService roomService) -> {
  if (status == RequestStatus.OK) {
    // Hold on to roomService reference for as long as you wish to stay in the room
  } else {
    // Handle error
  }
});

// With optional member update notification:
this.roomExpress.joinRoom(
    joinRoomOptions,
    (RequestStatus status, RoomService roomService) -> {
      if (status == RequestStatus.OK) {
        // Hold on to roomService reference for as long as you wish to stay in the room
      } else {
        // Handle error
      }
    },
    (Member[] members) -> {
      // Do something with room members
    });

✂ Unchanged content not shown

JoinRoomOptionsBuilder#Copied URL

Name Type Default Description
withRoomId (required) String Id of channel to view
withRoomAlias (optional) String Alias, alternative to ID
withCapabilities (required) String[] The list of all capabilities to subscribe with.
withRole (optional) MemberRole MemberRole.AUDIENCE The Member Role to join with
withScreenName (optional) String The member screen name to join with. A random string will be generated if not provided.
withStreams (optional) Stream[] [] The member streams to join with. Empty if not provided
buildJoinRoomOptions none Builds the JoinRoomOptions

Subscribe to a Member's Stream#Copied URL

Current version: Subscribe to a Member's Stream

Deprecated version:

Subscribe to a room member's stream and automatically handle audio and video state changes.

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.RoomExpress;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.express.SubscribeToMemberStreamOptions;
import com.phenixrts.room.ImmutableRoom;
import com.phenixrts.room.Member;
import com.phenixrts.room.Stream;
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;

final RoomExpress roomExpress = ...;  // previously obtained
final ImmutableRoom room = ...;  // previously obtained
final SurfaceView view = ...;  // previously obtained

final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

// Just an example showing how to get a stream from a member.
// In a real-world app you would want to subscribe to the room-members-observable on the room
// to receive updates when the list of members changes, and then subscribe to the streams-observable
// on each member to access their streams.
final Member member = room.getObservableMembers().getValue()[0];
final Stream memberStream = member.getObservableStreams().getValue()[0];

final SubscribeToMemberStreamOptions options =
    RoomExpressFactory.createSubscribeToMemberStreamOptionsBuilder()
        .withRenderer(renderSurface)
        .buildSubscribeToMemberStreamOptions();

roomExpress.subscribeToMemberStream(
    memberStream,
    options,
    (status, subscriber, renderer) -> {
      if (status != RequestStatus.OK) {
        // Handle subscribe error
        return;
      }

// Important: Store subscriber reference, otherwise we will stop subscription immediately:
      //currentSubscriber = subscriber;
    });

✂ Unchanged content not shown

SubscribeToMemberStreamOptionsBuilder#Copied URL

Name Type Default Description
withCapabilities (optional) String[] [] The list of all capabilities to subscribe with
withRenderer (optional) AndroidVideoRenderSurface none Render surface on which to display stream. If none of the withRenderer... methods are called, no renderer will be instantiated.
withRenderer (optional) none false Will trigger instantiation of renderer. Useful for audio only type streams that do not require a render surface
withRendererOptions (optional) RendererOptions none Options passed to renderer. Will trigger instantiation of renderer
withMonitor (optional) MonitorOptions.SetupFailedCallback, MonitorOptions.StreamEndedCallback, MonitorOptions none Options for monitoring a subscriber for failure
withConnectOptions (optional) String[] [] List of options for subscribing
withTags (optional) String[] [] Tags for the stream
buildSubscribeToMemberStreamOptions none Builds the SubscribeToMemberStreamOptions

Publish to a Room#Copied URL

Current version: Publish to a Room

Deprecated version:

Publish local or remote media to a room. An error will be returned if a room corresponding to the Room Options passed does not exist. If you have not entered the room via joinRoom or publishToRoom methods then a model for Self will be created.

Copy

import android.view.SurfaceView;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.express.PCastExpressFactory;
import com.phenixrts.express.PublishOptions;
import com.phenixrts.express.PublishRemoteOptions;
import com.phenixrts.express.PublishToRoomOptions;
import com.phenixrts.express.RoomExpress;
import com.phenixrts.express.RoomExpressFactory;
import com.phenixrts.pcast.DeviceCapability;
import com.phenixrts.pcast.FacingMode;
import com.phenixrts.pcast.RendererOptions;
import com.phenixrts.pcast.UserMediaOptions
import com.phenixrts.pcast.android.AndroidVideoRenderSurface;
import com.phenixrts.room.MemberRole;
import com.phenixrts.room.RoomOptions;
import com.phenixrts.room.RoomServiceFactory;
import com.phenixrts.room.StreamType;

final RoomExpress roomExpress = ...;  // previously obtained
final SurfaceView view = ...;  // previously obtained

final AndroidVideoRenderSurface renderSurface = new AndroidVideoRenderSurface(view.getHolder());

final UserMediaOptions mediaConstraints = new UserMediaOptions();
// Customize constraints if needed

final PublishOptions publishOptions = PCastExpressFactory.createPublishOptionsBuilder()
    .withCapabilities(new String[]{"hd", "streaming"})
    .withMediaConstraints(mediaConstraints)
    .withPreviewRenderer(renderSurface)
    .buildPublishOptions();

// Using RoomOptions means that the room may or may not already exist.
// If the room ID is known in advance, it is recommended to use `withRoomId` instead
// of `withRoomOptions` when assembling the `PublishToRoomOptions` below
final RoomOptions roomOptions = RoomServiceFactory.createRoomOptionsBuilder()
    .withName("MyAwesomeRoom")
    .buildRoomOptions();

final PublishToRoomOptions localPublishToRoomOptions =
    RoomExpressFactory.createPublishToRoomOptionsBuilder()
        .withStreamType(StreamType.USER)
        .withMemberRole(MemberRole.PARTICIPANT)
        .withRoomOptions(roomOptions)
        .withPublishOptions(publishOptions)
        .buildPublishToRoomOptions();

roomExpress.publishToRoom(
    localPublishToRoomOptions,
    (publishStatus, roomService, publisher, previewRenderer) -> {
      if (publishStatus != RequestStatus.OK) {
        // Handle channel publish error
        return;
      }

// Important: Store publisher reference, otherwise we will stop publishing again immediately:
      currentPublisher = publisher;
    }
);

// OR for a remote stream:
final PublishRemoteOptions remotePublishOptions = PCastExpressFactory
    .createPublishRemoteOptionsBuilder()
    .withStreamUri("http://example.com/mystream.mp4")
    .buildPublishRemoteOptions();

final PublishToRoomOptions remotePublishToRoomOptions =
    RoomExpressFactory.createPublishToRoomOptionsBuilder()
        .withStreamType(StreamType.USER)
        .withMemberRole(MemberRole.PARTICIPANT)
        .withRoomOptions(roomOptions)
        .withPublishRemoteOptions(remotePublishOptions)
        .buildPublishToRoomOptions();

// Remaining code is the same as for local stream

✂ Unchanged content not shown

PublishToRoomOptionsBuilder#Copied URL

Name Type Default Description
withRoomOptions (required) RoomOptions If omitted, then withRoomId needs to be provided.
withRoomId (required) String ID of room to publish to. If omitted, then withRoomOptions needs to be provided.
withPublishOptions (required) PublishOptions Either local or remote publish options are required
withPublishRemoteOptions (required) PublishRemoteOptions Either local or remote publish options are required
withMemberRole (required) MemberRole Role of member to join room as (used if not already in room). See Member Roles
withStreamType (required) StreamType Type of stream to publish. See Stream Types
withScreenName (optional) String automatically generated Screen name of self member
withViewerStreamSelectionStrategy (optional) StreamSelectionStrategy StreamSelectionStrategy.MOST_RECENT Stream Selection Strategy
withWildcardTokens (optional) true Generate wildcard stream tokens to be appended to member's stream uri. Reduces time for subscribing to published stream.
buildPublishToRoomOptions none Builds the PublishToRoomOptions

PCast#Copied URL

Newer versions of PCast™ require tokens (e.g., withStreamToken or withAuthenticationToken), and not including tokens will result in a failure such as bad-request.

Connect and Authenticate#Copied URL

Current version: Connect and Authenticate

Deprecated version:

Follow the example for connecting and authenticating to PCast™.

Copy

import android.util.Log;
import com.phenixrts.pcast.PCast;
import com.phenixrts.pcast.RequestStatus;

// Obtained via the EdgeAuth library
String authenticationToken = ...;
// Previously initialized
PCast pcast = ...;

pcast.start(
    authenticationToken,
    new PCast.AuthenticationCallback() {
        @Override
        public void onEvent(
            PCast pcast,
            RequestStatus requestStatus,
            String sessionId) {
                if (requestStatus == RequestStatus.OK) {
                    Log.i("Phenix SDK Example", "PCast started...");
                } else {
                    Log.e("Phenix SDK Example", "Failed to start PCast...");
                }
        }
    },
    new PCast.OnlineCallback() {
        @Override
        public void onEvent(PCast pcast) {
            Log.i("Phenix SDK Example", "We are online...");
        }
    },
    new PCast.OfflineCallback() {
        @Override
        public void onEvent(PCast pcast) {
            Log.i("Phenix SDK Example", "We are offline...");
        }
    });

Connect and Authenticate Parameters#Copied URL

Name Type Description
authenticationToken (required) string The authentication token generated using the Phenix EdgeAuth library
authenticationCallback (required) PCast.AuthenticationCallback Called upon successful authentication or when authentication failed or has to be redone. Upon successful authentication, the authenticationCallback will be called with status=RequestStatus.OK. If at any time a new authenticationToken is required, then the authenticationCallback is called with status=RequestStatus.UNAUTHORIZED to indicate that we are no longer authenticated.
onlineCallback (required) PCast.OnlineCallback Called when the client is connected to the streaming platform
offlineCallback (required) PCast.OfflineCallback Called when the client is disconnected from the streaming platform. Ongoing streams may continue while we are temporarily disconnected. However, no new streams can be started while being disconnected. The client automatically tries to reconnect and will call onlineCallback when it succeeds in doing so or eventually call authenticationCallback to indicate that re-authentication is required.

Authentication Callback Status Codes#Copied URL

Status Valid Fields Description
RequestStatus.OK sessionId Authentication succeeded, the sessionId is populated
RequestStatus.UNAUTHORIZED none Authentication failed or re-authentication required
varies none Authentication failed for other reasons

Get Local User Media#Copied URL

Current version: Get Local User Media

Deprecated version:

Please follow the self explanatory example for getting local user media.

Copy

import com.phenixrts.pcast.FacingMode;
import com.phenixrts.pcast.PCast;
import com.phenixrts.pcast.UserMediaOptions;
import com.phenixrts.pcast.UserMediaStream;
import com.phenixrts.pcast.android.AndroidPCastFactory;

// Previously initialized and started
PCast pcast = ...;

UserMediaOptions gumOptions = new UserMediaOptions();

// Customize options if desired
gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FACING_MODE, Arrays.asList(new DeviceConstraint(FacingMode.USER)));
gumOptions.getAudioOptions().enabled = false;

pcast.getUserMedia(
    gumOptions,
    new PCast.UserMediaCallback() {
        @Override
        public void onEvent(
            PCast pcast,
            RequestStatus status,
            UserMediaStream userMediaStream) {
                // Check status and store 'userMediaStream'
        }
    });

Get Local User Media Parameters#Copied URL

Name Type Description
options (required) UserMediaOptions The options defining the requested user media stream
userMediaCallback (required) PCast.UserMediaCallback Upon acquiring of the user media stream, the userMediaCallback will be called with status=RequestStatus.OK. If the user media is currently used by another application, then you may receive a code status=RequestStatus.CONFLICT . If the operation fails with status=RequestStatus.FAILED then please check the logs for more information

Device Capability#Copied URL

Name Description
DeviceCapability.WIDTH Width in pixels
DeviceCapability.HEIGHT Height in pixels
DeviceCapability.FRAME_RATE Number of frames per second
DeviceCapability.FACING_MODE Facing mode
DeviceCapability.FLASH_MODE Flash mode
DeviceCapability.DEVICE_ID Device ID string ( obtain from here)
DeviceCapability.LOCATION Device Location
DeviceCapability.POLAR_PATTERN Polar pattern
DeviceCapability.AUDIO_ECHO_CANCELATION_MODE Audio echo cancelation mode

Constraint Type#Copied URL

Name Description
ConstraintType.MIN Hard constraint: Capability must have at least the specified value
ConstraintType.MAX Hard constraint: Capability must have at most the specified value
ConstraintType.EXACT Hard constraint: Capability must have exactly the specified value
ConstraintType.IDEAL Soft constraint: Capability should have specified value, but other values are acceptable (default)

Facing Mode#Copied URL

Name Description
FacingMode.AUTOMATIC Select a facing mode automatically (default)
FacingMode.ENVIRONMENT Facing the surrounding environment (e.g., back camera)
FacingMode.USER Facing the user (e.g., front camera)

Flash Mode#Copied URL

Only applicable to video devices

Name Description
FlashMode.AUTOMATIC Flash is turned on automatically when needed (default)
FlashMode.ALWAYS_ON Flash is on (if available)
FlashMode.ALWAYS_OFF Flash is off

Device Location#Copied URL

Name Description
Location.AUTOMATIC Select any device (default)
Location.UPPER Mounted on top of phone/tablet
Location.LOWER Mounted at bottom of phone/tablet

Polar Pattern#Copied URL

Only applicable to audio devices

Name Description
PolarPattern.AUTOMATIC Automatically select pattern (default)
PolarPattern.OMNIDIRECTIONAL Equally sensitive to sound from any direction
PolarPattern.CARDIOID Most sensitive to sound from the direction in which the data source points and is (nearly) insensitive to sound from the opposite direction
PolarPattern.SUBCARDIOID Most sensitive to sound from the direction in which the data source points and is less sensitive to sound from the opposite direction

Note: This option is currently not supported on Android

Audio Echo Cancelation Mode#Copied URL

Only applicable to audio devices

Name Description
AudioEchoCancelationMode.AUTOMATIC Automatically select AEC mode (default)
AudioEchoCancelationMode.ON Enable AEC if available
AudioEchoCancelationMode.OFF Disable AEC

Note (as of v2019.2.0): Automatic mode is currently always set to "off" on Android.

Note 2 (as of v2019.2.0): AudioEchoCancelationMode must be set to ON in the UserMediaOptions for all published streams and RendererOptions for all subscribed streams in order for AEC to work reliably on all Android devices.

Updating Options#Copied URL

Sometimes you find it useful to change the camera while a stream is running or just would like to turn on the flash light temporarily.

Copy

import com.phenixrts.pcast.UserMediaOptions;
import com.phenixrts.pcast.UserMediaStream;

// Previously obtained via 'getUserMedia'
UserMediaStream userMediaStream = ...;

// Previously initialized and used with 'getUserMedia'
UserMediaOptions gumOptions = new UserMediaOptions();

gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FACING_MODE, Arrays.asList(new DeviceConstraint(FacingMode.ENVIRONMENT)));
gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.FLASH_MODE, Arrays.asList(new DeviceConstraint(FlashMode.ALWAYS_ON)));
gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.HEIGHT,
    Arrays.asList(new DeviceConstraint(720, ConstraintType.EXACT)));
gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.WIDTH,
    Arrays.asList(
        new DeviceConstraint(800, ConstraintType.MIN),
        new DeviceConstraint(1500, ConstraintType.MAX)));

userMediaStream.applyOptions(gumOptions);

Enumerating Source Devices#Copied URL

Current version: Enumerating Source Devices

Deprecated version:

You can get a list of available source devices.

Copy

import android.util.Log;
import com.phenixrts.pcast.MediaType;
import com.phenixrts.pcast.PCast;
import com.phenixrts.pcast.SourceDeviceInfo;

// Previously initialized and started
PCast pcast = ...;

pcast.enumerateSourceDevices(
    MediaType.VIDEO,
    new PCast.EnumerateSourceDevicesCallback() {
        @Override
        public void onEvent(PCast pcast, SourceDeviceInfo[] devices) {
            // Store devices as needed
        }
    });

Enumerating Source Devices Parameters#Copied URL

Name Type Description
mediaType (required) MediaType The media type for which to enumerate source devices

SourceDeviceInfo fields#Copied URL

Name Type Description
id String Source device ID
name String Source device Name
mediaType MediaType Source device media type
deviceType SourceDeviceType Source device type
facingMode FacingMode Source device facing mode

Media Type#Copied URL

Name Description
MediaType.VIDEO Video
MediaType.AUDIO Audio

Source Device Type#Copied URL

Name Description
SourceDeviceType.NULL Null device (e.g. blank screen or silence)
SourceDeviceType.PHYSICAL Physical device (e.g. camera or microphone)
SourceDeviceType.SYSTEM_OUTPUT System output capture (screencast)

Screencasting android 5.0 or later#Copied URL

Current version: Screencasting

Deprecated version:

You can also stream the screen of your phone.

In order to do this, you must first enumerate the available source devices to find the screencast device ID.

Find the screencast device ID

Copy

import android.util.Log;
import com.phenixrts.pcast.MediaType;
import com.phenixrts.pcast.PCast;
import com.phenixrts.pcast.SourceDeviceInfo;
import com.phenixrts.pcast.SourceDeviceType;

// Previously initialized and started
PCast pcast = ...;

pcast.enumerateSourceDevices(
    MediaType.VIDEO,
    new PCast.EnumerateSourceDevicesCallback() {
        @Override
        public void onEvent(PCast pcast, SourceDeviceInfo[] devices) {
            for (SourceDeviceInfo info : devices) {
                if (info.sourceDeviceType == SourceDeviceType.SYSTEM_OUTPUT) {
                    Log.i("Phenix SDK Example", "Screencasting is available");
                    String screenCaptureDeviceId = info.id;
                    // Store screenCaptureDeviceId
                }
            }
        }
    });

pcast.enumerateSourceDevices();

The screen capture device requires a valid android.media.projection.MediaProjection object to be passed to the SDK before it can be used. The MediaProjection must stay valid for the duration of the screencast.

Next, pass a valid android.media.projection.MediaProjection object

Copy

import android.media.projection.MediaProjection;
import com.phenixrts.pcast.android.AndroidPCastFactory;

// Previously obtained by calling
// android.media.projection.MediaProjectionManager.getMediaProjection(),
// see Android API reference.
MediaProjection mediaProjection = ...;

AndroidPCastFactory.setMediaProjection(mediaProjection);

Finally, pass the screen capture device ID

Next, pass the screen capture device ID to getUserMedia() in the user media options.

Copy

import com.phenixrts.pcast.FacingMode;
import com.phenixrts.pcast.PCast;
import com.phenixrts.pcast.UserMediaOptions;
import com.phenixrts.pcast.UserMediaStream;

// Previously initialized and started
PCast pcast = ...;

// Found by calling enumerateSourceDevices() as described above
String screenCaptureDeviceId = ...;

UserMediaOptions gumOptions = new UserMediaOptions();

gumOptions.getVideoOptions().capabilityConstraints.put(
    DeviceCapability.DEVICE_ID, Arrays.asList(new DeviceConstraint(screenCaptureDeviceId)));

Please follow the self explanatory code snippets for understanding above steps.

## Publish a Stream\#Copied URL

**Current version:** [Publish a Stream](/content/docs/sdk_ref/android/sdk-pcast/#publish-a-stream/index.html)

**Deprecated version:**

Copy

import android.util.Log; import com.phenixrts.pcast.MediaStream; import com.phenixrts.pcast.PCast; import com.phenixrts.pcast.Publisher; import com.phenixrts.pcast.RequestStatus; import com.phenixrts.pcast.StreamEndedReason; import com.phenixrts.pcast.UserMediaOptions; import com.phenixrts.pcast.UserMediaStream;

// Previously initialized and started PCast pcast = ...; // Previously obtained via EdgeAuth library String streamToken = ...; // Previously obtained via either PCast.subscribe() // or UserMediaStream.getMediaStream() MediaStream mediaStream = ...;

String[] tags = { "my-tag" };

pcast.publish( streamToken, mediaStream, new PCast.PublishCallback() { @Override public void onEvent( PCast pcast, RequestStatus requestStatus, Publisher publisher) { // Check status and store 'publisher'

// The "streamId" of the publisher String streamId = publisher.getStreamId();

if (publisher.hasEnded()) { // Checks if the publisher has ended }

// Attach publisher ended callback publisher.setPublisherEndedCallback( new Publisher.PublisherEndedCallback() { @Override public void onEvent( Publisher publisher, StreamEndedReason reason, String reasonDescription) { // Called when the stream has ended Log.i("Phenix SDK Example", "Publish stream ended with reason ["
+ reasonDescription + "]"); } });

// To stop later publisher.stop("I-am-done-publishing"); } }, tags);


### Publishing a Stream Parameters\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| streamToken _(required)_ | String | The publish token is generated using the Phenix [EdgeAuth](https://github.com/PhenixRTS/EdgeAuth) library |
| mediaStream _(required)_ | MediaStream | The user media stream acquired through PCast.subscribe(...) or locally with UserMediaStream.getMediaStream() |
| publishCallback _(required)_ | PCast.PublishCallback | Called upon completion of the operation |
| tags _(optional)_ | String\[\] | Tags that will be provided with the stream notifications to your backend callback endpoint |

### StreamEndedReason\#Copied URL

| Reason | Description |
| --- | --- |
| StreamEndedReason.ENDED | The stream ended normally |
| StreamEndedReason.FAILED | The stream failed |
| StreamEndedReason.CENSORED | The stream was censored |
| StreamEndedReason.MAINTENANCE | A maintenance event caused this stream to be terminated |
| StreamEndedReason.CAPACITY | The stream was terminated due to capacity limitations |
| StreamEndedReason.APP\_BACKGROUND | The stream was terminated due to the mobile app entering into the background |
| StreamEndedReason.CUSTOM | A custom termination reason is provided in the "reasonDescription" field |

## View a Stream\#Copied URL

**Current version:** [View a Stream](/content/docs/sdk_ref/android/sdk-pcast/#view-a-stream/index.html)

**Deprecated version:**

In order to view a stream you have to supply a Surface for the Renderer to draw on.

Copy

import com.phenixrts.pcast.MediaStream; import com.phenixrts.pcast.Renderer; import com.phenixrts.pcast.RendererStartStatus; import com.phenixrts.pcast.android.AndroidVideoRenderSurface;

// Previously obtained via either PCast.subscribe // or PhenixUserMediaStream.mediaStream MediaStream mediaStream = ...;

// Previously obtained, e.g., from a SurfaceView Surface renderSurface = ...;

Renderer renderer = mediaStream.createRenderer();

RendererStartStatus status = renderer.start(new AndroidVideoRenderSurface(renderSurface));

if (status == RendererStartStatus.OK) { Log.i("Phenix SDK Example", "Renderer started successfully"); } else { Log.e("Phenix SDK Example", "Renderer start failed"); }

// To stop later renderer.stop();


### Renderer options\#Copied URL

It is possible to pass additional options when creating a renderer.

Copy

import com.phenixrts.pcast.AspectRatioMode; import com.phenixrts.pcast.MediaStream; import com.phenixrts.pcast.Renderer; import com.phenixrts.pcast.RendererOptions;

// Previously obtained via either PCast.subscribe or UserMediaStream.mediaStream MediaStream mediaStream = ...;

RendererOptions options = new RendererOptions(); options.aspectRatioMode = AspectRatioMode.FILL;

Renderer renderer = mediaStream.createRenderer(options);


#### Properties

| Name | Type | Description |
| --- | --- | --- |
| aspectRatioMode _(optional)_ | [AspectRatioMode](/content/docs/sdk_ref/android/sdk-pcast-2022/#aspect-ratio-mode/index.html) | How to fill available video render surface |
| audioEchoCancelationMode _(optional)_ | [AudioEchoCancelationMode](/content/docs/sdk_ref/android/prior-versions-android/#audio-echo-cancelation-mode/index.html) | Audio echo cancelation mode |
| hardwareAcceleratedDecodingMode _(optional)_ | [HardwareAcceleratedDecodingMode](/content/docs/sdk_ref/android/prior-versions-android/#hardware-accelerated-decoding-mode/index.html) | Hardware accelerated decoding mode |

#### Aspect Ratio Mode

| Name | Description |
| --- | --- |
| AspectRatioMode.AUTOMATIC | Defaults to fill |
| AspectRatioMode.FILL | Fill entire render area. Video may be truncated |
| AspectRatioMode.LETTERBOX | Black bars are added on sides or top/bottom of render area, video will not be truncated |

Note: **This option is currently only supported for Real-Time streams**

#### Hardware Accelerated Decoding Mode

| Name | Description |
| --- | --- |
| HardwareAcceleratedDecodingMode.AUTOMATIC | Use hardware decoding on certified devices |
| HardwareAcceleratedDecodingMode.ON | Always use hardware decoding |
| HardwareAcceleratedDecodingMode.OFF | Always use software decoding |

## Room\#Copied URL

Newer versions of [Room](/content/docs/sdk_ref/android/sdk-room/index.html) do not support certain arguments in

Newer versions of [Room](/content/docs/sdk_ref/android/sdk-room/index.html) do not support wildcard tokens in the PhenixPublishToRoomOptionsBuilder.

## Initializing a Room\#Copied URL

**Current version:** [Initializing](/content/docs/sdk_ref/android/sdk-room/#initializing/index.html)

**Deprecated version:**

First you will need to initialize a room service object. This object is used for creating, joining, and leaving a room. As well, use this object for managing the room you enter (active room), members, and the model of your [Self](/content/docs/sdk_ref/android/prior-versions-android/#instantiate-self-member-model/index.html).

Note: PCast™ must be initialized and started when invoking `createRoomService` so that a valid session ID is present.

Copy

import android.content.Context;

import com.phenixrts.environment.android.AndroidContext; import com.phenixrts.pcast.PCast; import com.phenixrts.room.RoomService; import com.phenixrts.room.RoomServiceFactory;

final PCast pcast = ...; // previously obtained final RoomService roomService = RoomServiceFactory.createRoomService(pcast);


### Initializing Parameters\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| pcast _(required)_ | PCast | Instantiated PCast™ object. Must already be authenticated |

### RoomService\#Copied URL

| Name | Signature | Returns | Description |
| --- | --- | --- | --- |
| getRoomInfo | (roomId, alias, callback) | [Room](/content/docs/sdk_ref/android/prior-versions-android/#room/index.html) | See [Get Room Info](/content/docs/sdk_ref/android/prior-versions-android/#get-room-info/index.html) |
| createRoom | (room, callback) | [Room](/content/docs/sdk_ref/android/prior-versions-android/#room/index.html) | See [Create a Room](/content/docs/sdk_ref/rest-api/room/#creating-a-room/index.html) |
| joinRoom | (roomId, alias, callback) | [Room](/content/docs/sdk_ref/android/prior-versions-android/#room/index.html) | See [Join a Room](/content/docs/sdk_ref/android/prior-versions-android/#join-a-room/index.html) |
| leaveRoom | (callback) | void | See [Leave a Room](/content/docs/sdk_ref/android/prior-versions-android/#leave-a-room/index.html) |
| destroyRoom | (callback) | void | See [Destroy a Room](/content/docs/sdk_ref/android/prior-versions-android/#destroy-a-room/index.html) |
| getSelf | () | Observable of [Member](/content/docs/sdk_ref/android/prior-versions-android/#member/index.html)) | Observable of self member |
| getObservableActiveRoom | () | Observable of [Room](/content/docs/sdk_ref/android/prior-versions-android/#member/index.html)) | Observable of the active room |

## Create a Room (deprecated)\#Copied URL

**Current version:** Creating a Room is no longer supported by the Android SDK. Please use the [REST API](/content/docs/sdk_ref/rest-api/room/#creating-a-room/index.html) to create a Room.

**Deprecated version:**

Creation of Rooms from client SDKs is deprecated. Rooms should be created by
the backend using the [REST API](/content/docs/sdk_ref/rest-api/room/#creating-a-room/index.html).

Create a room with the provided details.

Copy

import com.phenixrts.common.RequestStatus; import com.phenixrts.room.Room; import com.phenixrts.room.RoomOptions; import com.phenixrts.room.RoomService; import com.phenixrts.room.RoomServiceFactory; import com.phenixrts.room.RoomType;

final RoomService roomService = ...; // previously obtained

final String roomName = "My Room Name"; final String description = "Deep thoughts only";

final RoomOptions roomOptions = RoomServiceFactory.createRoomOptionsBuilder() .withName(roomName) .withDescription(description) .withType(RoomType.MULTI_PARTY_CHAT) .buildRoomOptions();

roomService.createRoom( roomOptions, (RoomService service, RequestStatus status, Room room) -> { if (status == RequestStatus.OK) { // Do something with room } else { // Handle error } });


### Create Room Parameters\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| options _(required)_ | [RoomOptions](/content/docs/sdk_ref/android/prior-versions-android/#roomoptionsbuilder/index.html) | Room creation options |
| callback _(required)_ | RoomService.CreateRoomCallback | Callback with the status of the request and the room model |

### Create Room Callback Arguments\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| roomService | [RoomService](/content/docs/sdk_ref/android/prior-versions-android/#roomservice/index.html) | The room service making the callback |
| status | RequestStatus | The status of the operation |
| room | [Room](/content/docs/sdk_ref/android/prior-versions-android/#room/index.html) | Immutable room object |

### Create Room Callback Status Codes\#Copied URL

| Status | Description |
| --- | --- |
| ok | Create room succeeded. This can also mean that the room already existed |
| _varies_ | Create room failed for other reasons |

### RoomOptionsBuilder\#Copied URL

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| withName _(required)_ | String |  | Name of room |
| withType _(required)_ | [RoomType](/content/docs/sdk_ref/android/prior-versions-android/#room-types/index.html) |  | Room type |
| withAlias _(optional)_ | String | _generated_ | Room Alias |
| withDescription _(optional)_ | String | _empty_ | Room description |
| buildRoomOptions | _none_ |  | Builds the `RoomOptions` |

## Join a Room\#Copied URL

**Current version:** Joining a Room is no longer supported by the Low-Level Android APIs. Use the [Room Express](/content/docs/sdk_ref/android/express-room/#join-a-room/index.html) API to join a Room.

**Deprecated version:**

Join a room with the [Self model](/content/docs/sdk_ref/android/prior-versions-android/#instantiate-self-member-model/index.html). After successfully joining a room that room becomes the active room and can be returned via the [getObservableActiveRoom](/content/docs/sdk_ref/android/prior-versions-android/#phenixroomservice/index.html) method.

Copy

import com.phenixrts.common.RequestStatus; import com.phenixrts.room.Room; import com.phenixrts.room.RoomService;

final RoomService roomService = ...; // previously obtained

// Either provide alias or roomId, other can be null or empty final String roomId = null; final String alias = "exampleRoom";

roomService.joinRoom(roomId, alias, (RoomService roomService, RequestStatus status, Room room) -> { if (status == RequestStatus.OK) { // Do something with room } else { // Handle error } });


### Join Room Parameters\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| roomId _(required)_ | String | ID of the room |
| alias _(optional)_ | String | Alternative to roomId - alias of the room |
| callback _(required)_ | RoomService.JoinRoomCallback | Callback with the status of the request and the room model |

### Join Room Callback Arguments\#Copied URL

### Join Room Callback Status Codes\#Copied URL

| Status | Description |
| --- | --- |
| ok | Join room succeeded |
| not-found | Join room failed. Room does not exist - create room first |
| _varies_ | Join room failed for other reasons |

## Destroy a Room\#Copied URL

**Current version:** Destroying a Room is no longer supported by the Android SDK. Please use the [REST API](/content/docs/sdk_ref/rest-api/room/#deleting-a-room/index.html) to delete a Room.

**Deprecated version:**

Destroys the current active room assuming your self member has the permissions.

Copy

import com.phenixrts.common.RequestStatus; import com.phenixrts.room.Room; import com.phenixrts.room.RoomService;

final RoomService roomService = ...; // previously obtained

roomService.destroyRoom((RoomService roomService, RequestStatus status) -> { if (status == RequestStatus.OK) { // Successfully destroyed room, no action required } else { // Handle error } });


### Destroy Room Parameters\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| callback _(required)_ | RoomService.DestroyRoomCallback | Callback with the status of the request |

### Destroy Room Callback Arguments\#Copied URL

| Name | Type | Description |
| --- | --- | --- |
| roomService | [RoomService](/content/docs/sdk_ref/android/prior-versions-android/#roomservice/index.html) | The room service making the callback |
| status | RequestStatus | The status of the operation |

### Destroy Room Callback Status Codes\#Copied URL

| Status | Description |
| --- | --- |
| ok | Destroy room succeeded |
| _varies_ | Destroy room failed for other reasons |

[PreviousDeprecated SDK](/content/docs/sdk_ref/android/android-deprecated/index.html) [NextChannel Express - 2022](/content/docs/sdk_ref/android/express-channel-2022/index.html)

Page Content

- [v2022.0.3 and Earlier](/content/docs/sdk_ref/android/prior-versions-android/#v202203-and-earlier/index.html)
- [PCast™ Express](/content/docs/sdk_ref/android/prior-versions-android/#pcast-express/index.html)
- [Initializing PCast™ Express](/content/docs/sdk_ref/android/prior-versions-android/#initializing-pcast-express/index.html)
- [PCastExpressOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#pcastexpressoptionsbuilder/index.html)
- [Publishing Local Media](/content/docs/sdk_ref/android/prior-versions-android/#publishing-local-media/index.html)
- [PublishOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#publishoptionsbuilder/index.html)
- [Publishing Remote Media (Ingest)](/content/docs/sdk_ref/android/prior-versions-android/#publishing-remote-media-ingest/index.html)
- [Publish Remote Options Parameters](/content/docs/sdk_ref/android/prior-versions-android/#publish-remote-options-parameters/index.html)
- [PublishRemoteOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#publishremoteoptionsbuilder/index.html)
- [Publish Remote Options Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#publish-remote-options-callback-arguments/index.html)
- [Subscribing to Published Media](/content/docs/sdk_ref/android/prior-versions-android/#subscribing-to-published-media/index.html)
- [Subscribe Options](/content/docs/sdk_ref/android/prior-versions-android/#subscribe-options/index.html)
- [ExpressSubscriber](/content/docs/sdk_ref/android/prior-versions-android/#expresssubscriber/index.html)
- [Monitor](/content/docs/sdk_ref/android/prior-versions-android/#monitor/index.html)
- [OptionalAction](/content/docs/sdk_ref/android/prior-versions-android/#optionalaction/index.html)
- [MonitorSetupFailedCallback Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#monitorsetupfailedcallback-callback-arguments/index.html)
- [MonitorStreamEndedCallback Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#monitorstreamendedcallback-callback-arguments/index.html)
- [Channel Express](/content/docs/sdk_ref/android/prior-versions-android/#channel-express/index.html)
- [View a Channel](/content/docs/sdk_ref/android/prior-versions-android/#view-a-channel/index.html)
- [View Channel Parameters](/content/docs/sdk_ref/android/prior-versions-android/#view-channel-parameters/index.html)
- [JoinChannelOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#joinchanneloptionsbuilder/index.html)
- [Stream Selection Strategy](/content/docs/sdk_ref/android/prior-versions-android/#stream-selection-strategy/index.html)
- [Express Join Channel Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#express-join-channel-callback-arguments/index.html)
- [View Channel Subscriber Callback Status Codes](/content/docs/sdk_ref/android/prior-versions-android/#view-channel-subscriber-callback-status-codes/index.html)
- [Publish to a Channel](/content/docs/sdk_ref/android/prior-versions-android/#publish-to-a-channel/index.html)
- [Publish To Channel Parameters](/content/docs/sdk_ref/android/prior-versions-android/#publish-to-channel-parameters/index.html)
- [PublishToChannelOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#publishtochanneloptionsbuilder/index.html)
- [ChannelOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#channeloptionsbuilder/index.html)
- [Publish To Channel Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#publish-to-channel-callback-arguments/index.html)
- [Create a Channel (deprecated)](/content/docs/sdk_ref/android/prior-versions-android/#create-a-channel-deprecated/index.html)
- [Express Create Channel Parameters](/content/docs/sdk_ref/android/prior-versions-android/#express-create-channel-parameters/index.html)
- [Express Create Channel Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#express-create-channel-callback-arguments/index.html)
- [Room Express](/content/docs/sdk_ref/android/prior-versions-android/#room-express/index.html)
- [Initializing Room Express](/content/docs/sdk_ref/android/prior-versions-android/#initializing-room-express/index.html)
- [RoomExpressOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#roomexpressoptionsbuilder/index.html)
- [Join a Room](/content/docs/sdk_ref/android/prior-versions-android/#join-a-room/index.html)
- [JoinRoomOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#joinroomoptionsbuilder/index.html)
- [Subscribe to a Member's Stream](/content/docs/sdk_ref/android/prior-versions-android/#subscribe-to-a-members-stream/index.html)
- [SubscribeToMemberStreamOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#subscribetomemberstreamoptionsbuilder/index.html)
- [Publish to a Room](/content/docs/sdk_ref/android/prior-versions-android/#publish-to-a-room/index.html)
- [PublishToRoomOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#publishtoroomoptionsbuilder/index.html)
- [PCast](/content/docs/sdk_ref/android/prior-versions-android/#pcast/index.html)
- [Connect and Authenticate](/content/docs/sdk_ref/android/prior-versions-android/#connect-and-authenticate/index.html)
- [Connect and Authenticate Parameters](/content/docs/sdk_ref/android/prior-versions-android/#connect-and-authenticate-parameters/index.html)
- [Authentication Callback Status Codes](/content/docs/sdk_ref/android/prior-versions-android/#authentication-callback-status-codes/index.html)
- [Get Local User Media](/content/docs/sdk_ref/android/prior-versions-android/#get-local-user-media/index.html)
- [Get Local User Media Parameters](/content/docs/sdk_ref/android/prior-versions-android/#get-local-user-media-parameters/index.html)
- [Device Capability](/content/docs/sdk_ref/android/prior-versions-android/#device-capability/index.html)
- [Constraint Type](/content/docs/sdk_ref/android/prior-versions-android/#constraint-type/index.html)
- [Facing Mode](/content/docs/sdk_ref/android/prior-versions-android/#facing-mode/index.html)
- [Flash Mode](/content/docs/sdk_ref/android/prior-versions-android/#flash-mode/index.html)
- [Device Location](/content/docs/sdk_ref/android/prior-versions-android/#device-location/index.html)
- [Polar Pattern](/content/docs/sdk_ref/android/prior-versions-android/#polar-pattern/index.html)
- [Audio Echo Cancelation Mode](/content/docs/sdk_ref/android/prior-versions-android/#audio-echo-cancelation-mode/index.html)
- [Updating Options](/content/docs/sdk_ref/android/prior-versions-android/#updating-options/index.html)
- [Enumerating Source Devices](/content/docs/sdk_ref/android/prior-versions-android/#enumerating-source-devices/index.html)
- [Enumerating Source Devices Parameters](/content/docs/sdk_ref/android/prior-versions-android/#enumerating-source-devices-parameters/index.html)
- [SourceDeviceInfo fields](/content/docs/sdk_ref/android/prior-versions-android/#sourcedeviceinfo-fields/index.html)
- [Media Type](/content/docs/sdk_ref/android/prior-versions-android/#media-type/index.html)
- [Source Device Type](/content/docs/sdk_ref/android/prior-versions-android/#source-device-type/index.html)
- [Screencasting android 5.0 or later](/content/docs/sdk_ref/android/prior-versions-android/#screencasting-object-object/index.html)
- [Publish a Stream](/content/docs/sdk_ref/android/prior-versions-android/#publish-a-stream/index.html)
- [Publishing a Stream Parameters](/content/docs/sdk_ref/android/prior-versions-android/#publishing-a-stream-parameters/index.html)
- [StreamEndedReason](/content/docs/sdk_ref/android/prior-versions-android/#streamendedreason/index.html)
- [View a Stream](/content/docs/sdk_ref/android/prior-versions-android/#view-a-stream/index.html)
- [Renderer options](/content/docs/sdk_ref/android/prior-versions-android/#renderer-options/index.html)
- [Room](/content/docs/sdk_ref/android/prior-versions-android/#room/index.html)
- [Initializing a Room](/content/docs/sdk_ref/android/prior-versions-android/#initializing-a-room/index.html)
- [Initializing Parameters](/content/docs/sdk_ref/android/prior-versions-android/#initializing-parameters/index.html)
- [RoomService](/content/docs/sdk_ref/android/prior-versions-android/#roomservice/index.html)
- [Create a Room (deprecated)](/content/docs/sdk_ref/android/prior-versions-android/#create-a-room-deprecated/index.html)
- [Create Room Parameters](/content/docs/sdk_ref/android/prior-versions-android/#create-room-parameters/index.html)
- [Create Room Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#create-room-callback-arguments/index.html)
- [Create Room Callback Status Codes](/content/docs/sdk_ref/android/prior-versions-android/#create-room-callback-status-codes/index.html)
- [RoomOptionsBuilder](/content/docs/sdk_ref/android/prior-versions-android/#roomoptionsbuilder/index.html)
- [Join a Room](/content/docs/sdk_ref/android/prior-versions-android/#join-a-room/index.html)
- [Join Room Parameters](/content/docs/sdk_ref/android/prior-versions-android/#join-room-parameters/index.html)
- [Join Room Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#join-room-callback-arguments/index.html)
- [Join Room Callback Status Codes](/content/docs/sdk_ref/android/prior-versions-android/#join-room-callback-status-codes/index.html)
- [Destroy a Room](/content/docs/sdk_ref/android/prior-versions-android/#destroy-a-room/index.html)
- [Destroy Room Parameters](/content/docs/sdk_ref/android/prior-versions-android/#destroy-room-parameters/index.html)
- [Destroy Room Callback Arguments](/content/docs/sdk_ref/android/prior-versions-android/#destroy-room-callback-arguments/index.html)
- [Destroy Room Callback Status Codes](/content/docs/sdk_ref/android/prior-versions-android/#destroy-room-callback-status-codes/index.html)

Copyright 2026 © [Phenix RTS](/content/site-root.html)

[Privacy Policy](/content/privacy-policy/index.html) \| [Terms of Service](/content/terms-of-service/index.html)

v2025-03-24T21:12:24.000Z