Player
The fundamental interface class for the RTE player, which implements the major functions of media playback.
code
Gets the error code.
public Constants.ErrorCode code();
- Since
- v4.5.0
Call timing
When an API call fails, you can call this method to get the error code.
Restrictions
None.
Returns
Error code. See ErrorCode.
getConfigs [2/3]
Gets the current player settings.
public void getConfigs(PlayerConfig config) throws RteException;
- Since
- v4.5.0
Call timing
Call this method after Player.
Restrictions
None.
Parameters
- config
- The player configuration object: PlayerConfig.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
getInfo
Gets the player state and the information about the media stream being played.
public void getInfo(PlayerInfo info) throws RteException;
- Since
- v4.5.0
You can obtain information about the player state and media stream through this method, such as audio sampling rate, video frame size.
Call timing
Call this method after Player.
Restrictions
None.
Parameters
- info
- The information of the player and the media stream. See PlayerInfo.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
getStats
Gets statistical information about the current media resource being played.
public void getStats(PlayerGetStatsCallback callback);
- Since
- v4.5.0
This method is used to obtain statistical information about the player, including decoding, rendering frame rate, audio and video bitrate, etc., and asynchronously returns the results through a callback function.
Call timing
Call this method after openWithUrl.
Restrictions
None.
Parameters
- callback
- An asynchronous callback used to notify the result and possible error information of obtaining the statistics. See the onResult callback in the PlayerGetStatsCallback class.
message
Gets the error message.
public String message();
- Since
- v4.5.0
Call timing
When an API call fails, you can use this method to retrieve error information to help troubleshoot the issue.
Restrictions
None.
Returns
The error message.muteAudio
Subscribes or unsubscribes to an audio stream.
public void muteAudio(boolean mute) throws RteException;
- Since
- v4.5.0
Audience member can call this method to decide whether to subscribe to the host's audio stream.
Call timing
Call this method after openWithUrl.
Restrictions
None.
Parameters
- mute
- Whether to subscribe to the audio stream of the host:
true
: Subscribe to the audio stream.false
: Do not subscribe to the audio stream.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
muteVideo
Subscribes or unsubscribes to a video stream.
public void muteVideo(boolean mute) throws RteException;
- Since
- v4.5.0
Audience member can call this method to decide whether to subscribe to the host's video stream.
Call timing
Call this method after openWithUrl.
Restrictions
None.
Parameters
- mute
- Whether to subscribe to the video stream of the host:
true
: Subscribe to the video stream.false
: Do not subscribe to the video stream.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
openWithUrl
Opens a URL.
public void openWithUrl(String url, long startTime, AsyncCallback callback);
- Since
- v4.5.0
This method can open a live stream via URL. If you want to speed up the process of opening a URL, you can call the preloadWithUrl method to preload the URL before calling the method.
If you fail to open the URL, you will receive the onStateChanged callback reporting the state as FAILED. At this time, you need to call stop first, then call openWithUrl to reopen the URL. If you have disabled autoplay, you can call play to play after opening the URL.
Call timing
Call this method after Player.
Restrictions
This method currently only supports playing URLs with the rte://
prefix.
Parameters
- url
- URLs with the
rte://
prefix. - startTime
- Reserved for future use.
- callback
- An asynchronous callback, used to notify the result of opening a URL. If an error occurs during the opening, you can get specific error information through the onResult callback in the AsyncCallback.
pause
Pauses the playback.
public void pause() throws RteException;
- Since
- v4.5.0
When you call play to play a URL, if you want to pause the playback, you can call this method. If you need to stop the playback, call stop.
Call timing
Call this method after play.
Restrictions
None.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
Player
Create a player object.
public Player(Rte rte, PlayerInitialConfig initialConfig);
- Since
- v4.5.0
Call timing
Call this method after initMediaEngine.
Restrictions
None.
Parameters
- rte
- One Rte object.
- initialConfigç
- Player object initialization settings. Currently you can set it as null.
play
Plays a URL.
public void play() throws RteException;
- Since
- v4.5.0
If you have disabled autoplay, when you successfully open a live stream through a URL by calling openWithUrl, you can call this method to play the stream.
Call timing
Call this method after you receive the onStateChanged callback reporting the OPEN_COMPLETED state.
Restrictions
This method currently only supports playing URLs with the rte://
prefix.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
preloadWithUrl
Preloads a URL resource.
public static void preloadWithUrl(String url) throws RteException;
- Since
- v4.5.0
After successful preloading, the speed of accessing URL resources can be accelerated when calling openWithUrl. When you need to use these resources, you can access them more quickly and shorten the waiting process.
Applicable scenarios
Before opening media resources, preloading can reduce the time for waiting and provide a smoother user experience.
Call timing
Call this method after openWithUrl.
Restrictions
This method currently only takes effect on URLs with the prefix rte://
. A maximum of 20 URLs can be preloaded. If exceeded, the newly preloaded URL will replace the oldest one.
Parameters
- url
- URLs with the
rte://
prefix.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
registerObserver
Registers the observer of the player.
public void registerObserver(PlayerObserver observer) throws RteException;
- Since
- v4.5.0
Before calling this method, you need to implement a class that inherits from PlayerObserver.
Call timing
Call this method after Player.
Restrictions
None.
Parameters
- observer
- The delegate instance. See PlayerObserver.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
setCanvas
Sets the view window for displaying the video.
public void setCanvas(Canvas canvas) throws RteException;
- Since
- v4.5.0
This method specifies a Canvas object to display the video. Once the the video stream sucessfully plays, the video image will be displayed on the specified canvas.
Call timing
Call this method after Player.
Restrictions
None.
Parameters
- canvas
- The Canvas object on which the video is rendered: Canvas
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
stop
Stops playing media resource.
public void pause() throws RteException;
- Since
- v4.5.0
After you successfully play the URL stream using play, call this method if you want to stop playing it. If you need to pause the playback, call pause.
If you fail to open the URL stream using openWithUrl, call this method first, and then call openWithUrl to reopen the URL.
Call timing
Call this method after openWithUrl.
Restrictions
None.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
setConfigs [2/3]
Sets the player configurations.
public void setConfigs(PlayerConfig config) throws RteException;
- Since
- v4.5.0
You can call this method to configuer the player, such as enabling autoplay and subscribing to video streams of a different resolution and bitrate.
Call timing
Call this method after Player.
Restrictions
None.
Parameters
- config
- The player configuration object: PlayerConfig.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.
unregisterObserver
Unregisters the player event observer.
public void unregisterObserver(PlayerObserver observer) throws RteException;
- Since
- v4.5.0
After you register the player event observer by calling registerObserver, if you want to unregister the observer, call this method.
Call timing
Call this method after registerObserver.
Restrictions
None.
Parameters
- observer
- The delegate instance. See PlayerObserver.
Exception
If the method call fails, the SDK throws RteException and returns an error message. You need to catch the exception and handle it.