Agora Java API Reference for Android

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
io.agora.rte.Player Class Reference

## Public Member Functions
| Player (Rte rte, PlayerInitialConfig initialConfig)
long | getNativeHandle ()
void | openWithUrl (String url, long startTime, AsyncCallback callback)
void | openWithCustomSourceProvider (PlayerCustomSourceProvider provider, long startTime, AsyncCallback callback)
void | openWithStream (Stream stream, AsyncCallback callback)
void | switchWithUrl (String url, boolean syncPts, AsyncCallback callback)
void | getStats (PlayerGetStatsCallback callback)
void | setCanvas (Canvas canvas) throws RteException
void | play () throws RteException
void | stop () throws RteException
void | pause () throws RteException
void | seek (long newTime) throws RteException
void | muteAudio (boolean mute) throws RteException
void | muteVideo (boolean mute) throws RteException
long | getPosition () throws RteException
void | getInfo (PlayerInfo info) throws RteException
void | getConfigs (PlayerConfig config) throws RteException
void | setConfigs (PlayerConfig config) throws RteException
void | registerObserver (PlayerObserver observer) throws RteException
void | unregisterObserver (PlayerObserver observer) throws RteException

## Static Public Member Functions
static void | preloadWithUrl (String url) throws RteException

## Protected Member Functions
void | finalize ()

## Detailed Description

The Player class can be used to play URL resources.

Since
  v4.4.0

## Constructor & Destructor Documentation

## ◆ Player()

io.agora.rte.Player.Player | ( | Rte | rte,
|  | PlayerInitialConfig | initialConfig
| ) |  |

Construct a Player object.

Since
  v4.4.0

Parameters

  rte | Rte object.
  initialConfig | PlayerInitialConfig initialization configuration object. Currently, a null pointer can be passed.

## Member Function Documentation

## ◆ preloadWithUrl()

static void io.agora.rte.Player.preloadWithUrl | ( | String | url | ) | throws RteException
| static

Preload URL, only valid for rte type URLs. This interface can speed up the openWithUrl operation. Up to 20 URLs can be preloaded. If the limit is exceeded, new preloads will replace old ones.

Since
  v4.4.0

Parameters

  url | rte type URL

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode ErrorCode.INVALID_ARGUMENT: The passed URL is empty or has an invalid format.

Returns
  void

## ◆ openWithUrl()

void io.agora.rte.Player.openWithUrl | ( | String | url,
|  | long | startTime,
|  | AsyncCallback | callback
| ) |  |

Open URL resource. Currently, the rte URLs and cdn URLs and files are supported. This interface can also be used to refresh the token of an already opened RTE URL. For RTE URL format definition and token refresh method description, refer to the doc: https://doc.shengwang.cn/doc/rtc/android/best-practice/playing-url

Since
  v4.4.0

Parameters

  url | The URL resource to open
  startTime | Set the starting position for playback, in ms.
  callback | Asynchronous callback to notify the result of the open operation. If an error occurs during open, it will enter the PlayerState.FAILED state. You need to call the stop method before calling openWithUrl again.
  error | Possible ErrorCode returns. At this time, the new_state value corresponds to PlayerState.FAILED. ErrorCode.OK: Success ErrorCode.DEFAULT: For specific reasons, see Error.Message, including the following situations: Failed to connect to the channel ErrorCode.INVALID_ARGUMENT: Invalid appid Invalid channelid Invalid uid ErrorCode.AUTHENTICATION_FAILED: Invalid token Token expired ErrorCode.INVALID_OPERATION: Engine not initialized

Returns
  void

## ◆ switchWithUrl()

void io.agora.rte.Player.switchWithUrl | ( | String | url,
|  | boolean | syncPts,
|  | AsyncCallback | callback
| ) |  |

Switch to a new URL. This interface can be used to switch to a new URL during playback.

Note
  - This method is only valid when the player opens a non-RTE URL.
  - Call this method when the sdk returns the player state as PlayerState.OPEN_COMPLETED.

Since
  v4.5.1

Parameters

  url | The URL resource to switch to.
  syncPts | Whether to synchronize the playback position (ms) after the switch operation: true: Synchronize the playback position. false: (Default)Do not synchronize the playback position.
  callback | Asynchronous callback to notify the result of the switch operation.
  error | Possible ErrorCode returns. ErrorCode.OK: Success ErrorCode.DEFAULT: Failed to switch to the new URL. ErrorCode.INVALID_ARGUMENT: The passed URL is empty or has an invalid format. ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. The opened URL is an RTE URL, switch to a new URL is not supported.

Returns
  void

## ◆ getStats()

void io.agora.rte.Player.getStats | ( | PlayerGetStatsCallback | callback | ) |

Get player playback statistics.

Since
  v4.4.0

Parameters

  callback | Asynchronous callback for statistical data.
  playerStats | Statistical values.
  error | Possible ErrorCode returns: ErrorCode.OK: Success

Returns
  void

## ◆ setCanvas()

void io.agora.rte.Player.setCanvas | ( | Canvas | canvas | ) | throws RteException

Set canvas. After the stream is successfully pulled, the video frame will be rendered on the set canvas.

Since
  v4.4.0

Parameters

  canvas | The canvas object used to render video frames.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_ARGUMENT: The canvas is null. ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ play()

void io.agora.rte.Player.play | ( |  | ) | throws RteException

Start stream playback.

Since
  v4.4.0

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ stop()

void io.agora.rte.Player.stop | ( |  | ) | throws RteException

Stop playback.

Since
  v4.4.0

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ pause()

void io.agora.rte.Player.pause | ( |  | ) | throws RteException

Pause playback.

Since
  v4.4.0

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ seek()

void io.agora.rte.Player.seek | ( | long | newTime | ) | throws RteException

Seek the playback position.

Since
  v4.5.1

Parameters

  newTime | The new playback position to seek to.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. The opened URL is an RTE URL, Seek is not supported.

Returns
  void

## ◆ muteAudio()

void io.agora.rte.Player.muteAudio | ( | boolean | mute | ) | throws RteException

Mute/unmute audio separately.

Since
  v4.4.0

Parameters

  mute | Whether to mute.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ muteVideo()

void io.agora.rte.Player.muteVideo | ( | boolean | mute | ) | throws RteException

Mute/unmute video separately.

Since
  v4.4.0

Parameters

  mute | Whether to mute.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.

Returns
  void

## ◆ getPosition()

long io.agora.rte.Player.getPosition | ( |  | ) | throws RteException

Get the playback position.

Since
  v4.5.1

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. The opened URL is an RTE URL, getPosition is not supported.

Returns
  The current playback position, in milliseconds.

## ◆ getInfo()

void io.agora.rte.Player.getInfo | ( | PlayerInfo | info | ) | throws RteException

Get player information.

Since
  v4.4.0

Parameters

  info | The object used to receive player information. After the interface call is successful, the player information will be copied to the info object.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. ErrorCode.INVALID_ARGUMENT: The info object is null.

Returns
  void

## ◆ getConfigs()

void io.agora.rte.Player.getConfigs | ( | PlayerConfig | config | ) | throws RteException

Get the configuration of Player object.

Since
  v4.4.0

Parameters

  config | The object used to receive PlayerConfig information.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. ErrorCode.INVALID_ARGUMENT: The config object is null.

Returns
  void

## ◆ setConfigs()

void io.agora.rte.Player.setConfigs | ( | PlayerConfig | config | ) | throws RteException

Configure the Player object.

Since
  v4.4.0

Parameters

  config | The object used to change the player configuration.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. ErrorCode.INVALID_ARGUMENT: The config object is null.

Returns
  voiod

## ◆ registerObserver()

void io.agora.rte.Player.registerObserver | ( | PlayerObserver | observer | ) | throws RteException

Register player observer.

Since
  v4.4.0

Parameters

  observer | The object used to receive player-related callbacks.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. ErrorCode.INVALID_ARGUMENT: The observer object is null.

Returns
  void

## ◆ unregisterObserver()

void io.agora.rte.Player.unregisterObserver | ( | PlayerObserver | observer | ) | throws RteException

Unregister player observer.

Since
  v4.4.0

Parameters

  observer | The object used to receive player-related callbacks.

Exceptions

  RteException | RteException.errorCode() may return the following ErrorCode: ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid. ErrorCode.INVALID_ARGUMENT: The observer object is null.

Returns
  void