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 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
rteRte object.
initialConfigPlayerInitialConfig 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
urlrte type URL
Exceptions
RteExceptionRteException.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, only rte URLs are supported, and cdn URLs and files are not supported. This interface can also be used to refresh the token of an already opened URL. For 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
urlThe URL resource to open
startTimeStart time [currently not supported]
callbackAsynchronous 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.
errorPossible 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

◆ getStats()

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

Get player playback statistics.

Since
v4.4.0
Parameters
callbackAsynchronous callback for statistical data.
playerStatsStatistical values.
errorPossible 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
canvasThe canvas object used to render video frames.
Exceptions
RteExceptionRteException.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
RteExceptionRteException.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
RteExceptionRteException.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
RteExceptionRteException.errorCode() may return the following ErrorCode:
  • ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.
Returns
void

◆ muteAudio()

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

Mute/unmute audio separately.

Since
v4.4.0
Parameters
muteWhether to mute.
Exceptions
RteExceptionRteException.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
muteWhether to mute.
Exceptions
RteExceptionRteException.errorCode() may return the following ErrorCode:
  • ErrorCode.INVALID_OPERATION: The corresponding internal Player object has been destroyed or is invalid.
Returns
void

◆ getInfo()

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

Get player information.

Since
v4.4.0
Parameters
infoThe object used to receive player information. After the interface call is successful, the player information will be copied to the info object.
Exceptions
RteExceptionRteException.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
configThe object used to receive PlayerConfig information.
Exceptions
RteExceptionRteException.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
configThe object used to change the player configuration.
Exceptions
RteExceptionRteException.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
observerThe object used to receive player-related callbacks.
Exceptions
RteExceptionRteException.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
observerThe object used to receive player-related callbacks.
Exceptions
RteExceptionRteException.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