Media Player Kit v1.3.0 API Reference for Android
io.agora.mediaplayer.AgoraMediaPlayerKit Class Reference

Public Member Functions

 AgoraMediaPlayerKit (Context context)
 
int open (String src, long startPos)
 
int play ()
 
int pause ()
 
int stop ()
 
int seek (long pos)
 
int mute (boolean mute)
 
boolean isMuted ()
 
int adjustPlayoutVolume (int volume)
 
int getPlayoutVolume ()
 
long getPlayPosition ()
 
long getDuration ()
 
int getState ()
 
int getStreamCount ()
 
int setView (View videoView)
 
int setRenderMode (int mode)
 
MediaStreamInfo getStreamInfo (int index)
 
int destroy ()
 
void registerPlayerObserver (MediaPlayerObserver playerObserver)
 
void unregisterPlayerObserver (MediaPlayerObserver playerObserver)
 
int registerVideoFrameObserver (VideoFrameObserver observer)
 
int registerAudioFrameObserver (AudioFrameObserver observer)
 
void unregisterVideoFrameObserver (VideoFrameObserver observer)
 
void unregisterAudioFrameObserver (AudioFrameObserver observer)
 
int setLogFilter (int filter)
 
int setLogFile (String filePath)
 
int selectAudioTrack (int index)
 
int changePlaybackSpeed (MediaPlayerPlaybackSpeed speed)
 
int setPlayerOption (String key, int value)
 
int setPlayerOptionString (String key, String value)
 
int setLoopCount (int loopCount)
 
int switchSrc (String src, boolean syncPts)
 
int addPreloadSrc (String src, long startPos)
 
int playPreload (String src)
 
String getPlayerSdkVersion ()
 

Static Public Member Functions

static void setAudioMode (MediaPlayerAudioMode audioMode)
 

Private Attributes

IMediaPlayerKit mediaPlayer = null
 

Detailed Description

Constructor & Destructor Documentation

◆ AgoraMediaPlayerKit()

io.agora.mediaplayer.AgoraMediaPlayerKit.AgoraMediaPlayerKit ( Context  context)

Creates an AgoraMediaPlayerKit instance.

Parameters
contextThe context of an Android Activity
Returns
the AgoraMediaPlayerKit instance

Member Function Documentation

◆ setAudioMode()

static void io.agora.mediaplayer.AgoraMediaPlayerKit.setAudioMode ( MediaPlayerAudioMode  audioMode)
static

Sets the audio mode.

You can call this method to set MediaPlayer Kit to use in-call volume or media volume:

  • When you use the Agora RTC Native SDK and MediaPlayer Kit at the same time, if the audio scenario of the Native SDK is GameStreaming(3), Agora recommends that you set the MediaPlayer Kit to use the media volume and integrate the helper at the same time.
  • When you use the Agora RTC Native SDK and MediaPlayer Kit at the same time, if the audio scenario of the Native SDK is not GameStreaming(3), Agora recommends that you set the MediaPlayer Kit to use the in-call volume.
Note
You must call this method before calling the open method.
Parameters
audioModeThe audio mode. See MediaPlayerAudioMode for details.

◆ open()

int io.agora.mediaplayer.AgoraMediaPlayerKit.open ( String  src,
long  startPos 
)

Open the media resource.

Parameters
srcThe path of the media resource. Both local path and online path are supported.
startPosThe starting position (ms) for playback. Default value is 0.
Returns

◆ play()

int io.agora.mediaplayer.AgoraMediaPlayerKit.play ( )

Plays the media resource.

After open() or pause() or seek(), you can call this method to play the media resource.

Returns

◆ pause()

int io.agora.mediaplayer.AgoraMediaPlayerKit.pause ( )

Pauses the playback.

To resume the playback, call the play method.

Returns

◆ stop()

int io.agora.mediaplayer.AgoraMediaPlayerKit.stop ( )

Stops the playback.

Returns

◆ seek()

int io.agora.mediaplayer.AgoraMediaPlayerKit.seek ( long  pos)

Seeks to a new playback position.

After successfully calling the method, you will receive the onPlayerEvent callback, reporting the result of the seek operation to the new playback position.

Parameters
posThe new playback position (ms).
Returns

◆ mute()

int io.agora.mediaplayer.AgoraMediaPlayerKit.mute ( boolean  mute)

Sets whether to mute the media resource.

Parameters
muteSets whether to mute the media resource:
  • true: Mute the media resource.
  • false: (default) Unmute the media resource.
Returns

◆ isMuted()

boolean io.agora.mediaplayer.AgoraMediaPlayerKit.isMuted ( )

Confirms whether the media resource is muted.

Returns
  • If the call succeeds, returns:
    • true: The media resource is muted.
    • false: (default) The media resource is not muted.
  • If the call fails, returns false.

◆ adjustPlayoutVolume()

int io.agora.mediaplayer.AgoraMediaPlayerKit.adjustPlayoutVolume ( int  volume)

Adjusts the local playback volume.

Parameters
volumeThe local playback volume, which ranges from 0 to 100:
  • 0: Mute.
  • 100: (default) The original volume.
Returns

◆ getPlayoutVolume()

int io.agora.mediaplayer.AgoraMediaPlayerKit.getPlayoutVolume ( )

Gets current local playback volume.

Returns
  • < 0: Failure. See MediaPlayerError for details.
  • Others: The call succeeds and returns current local playback volume.

◆ getPlayPosition()

long io.agora.mediaplayer.AgoraMediaPlayerKit.getPlayPosition ( )

Gets current playback progress.

Returns
  • < 0: Failure. See MediaPlayerError for details.
  • Others: The call succeeds and returns current playback progress (ms).

◆ getDuration()

long io.agora.mediaplayer.AgoraMediaPlayerKit.getDuration ( )

Gets the duration of the media resource.

Returns
  • < 0: Failure. See MediaPlayerError for details.
  • Others: The call succeeds and returns the total duration (ms) of the media resource.

◆ getState()

int io.agora.mediaplayer.AgoraMediaPlayerKit.getState ( )

Gets current playback state.

Returns

◆ getStreamCount()

int io.agora.mediaplayer.AgoraMediaPlayerKit.getStreamCount ( )

Gets the number of the media streams in the media resource.

Returns
  • < 0: Failure. See MediaPlayerError for details.
  • Others: The call succeeds and returns the number of the media streams in the media resource.

◆ setView()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setView ( View  videoView)

Sets the player's render view.

Parameters
videoViewThe player's render view.
Returns

◆ setRenderMode()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setRenderMode ( int  mode)

Sets the player's render mode.

Parameters
modeThe player's render mode
Returns

◆ getStreamInfo()

MediaStreamInfo io.agora.mediaplayer.AgoraMediaPlayerKit.getStreamInfo ( int  index)

Gets the detailed information of the media stream.

Parameters
indexThe index of the media stream.
Returns
  • If the call succeeds, returns the detailed information of the media stream. See MediaStreamInfo for details.
  • If the call fails, returns NULL.

◆ destroy()

int io.agora.mediaplayer.AgoraMediaPlayerKit.destroy ( )

Destroys an AgoraMediaPlayerKit instance.

Returns

◆ registerPlayerObserver()

void io.agora.mediaplayer.AgoraMediaPlayerKit.registerPlayerObserver ( MediaPlayerObserver  playerObserver)

Registers a player observer.

Parameters
playerObserverThe player observer, listening for events during the playback. See MediaPlayerObserver for details.

◆ unregisterPlayerObserver()

void io.agora.mediaplayer.AgoraMediaPlayerKit.unregisterPlayerObserver ( MediaPlayerObserver  playerObserver)

Unregisters a player observer.

Parameters
playerObserverThe player observer, listening for events during the playback. See MediaPlayerObserver for details.

◆ registerVideoFrameObserver()

int io.agora.mediaplayer.AgoraMediaPlayerKit.registerVideoFrameObserver ( VideoFrameObserver  observer)

Registers a video observer.

Parameters
observerThe video observer, reporting the reception of each video frame. See VideoFrameObserver for details.
Returns

◆ registerAudioFrameObserver()

int io.agora.mediaplayer.AgoraMediaPlayerKit.registerAudioFrameObserver ( AudioFrameObserver  observer)

Registers an audio observer.

Parameters
observerThe audio observer, reporting the reception of each audio frame. See AudioFrameObserver for details.
Returns

◆ unregisterVideoFrameObserver()

void io.agora.mediaplayer.AgoraMediaPlayerKit.unregisterVideoFrameObserver ( VideoFrameObserver  observer)

Unregisters a video observer.

Parameters
observerThe video observer. See VideoFrameObserver for details.

◆ unregisterAudioFrameObserver()

void io.agora.mediaplayer.AgoraMediaPlayerKit.unregisterAudioFrameObserver ( AudioFrameObserver  observer)

Unregisters an audio observer.

Parameters
observerThe audio observer. See AudioFrameObserver for details.

◆ setLogFilter()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setLogFilter ( int  filter)

Sets the output log level of the mediaplayer kit.

You can use one or a combination of the filters. The log level follows the sequence of OFF, CRITICAL, ERROR, WARNING, INFO, and DEBUG. Choose a level to see the logs preceding that level. For example, if you set the log level to WARNING, you see the logs within levels CRITICAL, ERROR, and WARNING.

Parameters
filterLog filter level:
  • LOG_FILTER_DEBUG(0x80f): Output all log information. Set your log filter as debug if you want to get the most complete log file.
  • LOG_FILTER_INFO(0x0f): Output CRITICAL, ERROR, WARNING, and INFO level log information. We recommend setting your log filter as this level.
  • LOG_FILTER_WARNING(0x0e): Outputs CRITICAL, ERROR, and WARNING level log information.
  • LOG_FILTER_ERROR(0x0c): Outputs CRITICAL and ERROR level log information.
  • LOG_FILTER_CRITICAL(0x08): Outputs CRITICAL level log information.
  • LOG_FILTER_OFF(0): Do not output any log information.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setLogFile()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setLogFile ( String  filePath)

Specifies the output log files of the mediaplayer kit.

Note
  • The default log file path is /sdcard/{package name}/agoraplayer.log.
  • Ensure that you call this method immediately after creating AgoraMediaPlayer, otherwise the output logs may not be complete.
Parameters
filePathThe absolute path of log files. Ensure that the directory for the log files exists and is writable.
Returns
  • 0: Success.
  • < 0: Failure.

◆ selectAudioTrack()

int io.agora.mediaplayer.AgoraMediaPlayerKit.selectAudioTrack ( int  index)

Selects the audio track used during playback.

After opening the media file, you can call this method to select the audio track used during playback.

Before calling this method, call the getStreamInfo method to get the audio track information of the current media stream. The streamIndex value of the audio track information is the index value of this method.

Parameters
indexThe index of the audio track.
Returns
  • 0: Success.
  • < 0: Failure.

◆ changePlaybackSpeed()

int io.agora.mediaplayer.AgoraMediaPlayerKit.changePlaybackSpeed ( MediaPlayerPlaybackSpeed  speed)

Changes the playback speed.

After opening the media file, you can call this method to change the playback speed.

Parameters
speedThe playback speed. See MediaPlayerPlaybackSpeed.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setPlayerOption()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setPlayerOption ( String  key,
int  value 
)

Sets the private options for the MediaPlayer Kit.

The MediaPlayer Kit supports setting private options by providing key and value. Under normal circumstances, you do not need to know the private option settings, and just use the default option settings.

Note
Calling this method before the open method.
Parameters
keykey.
valuevalue.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setPlayerOptionString()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setPlayerOptionString ( String  key,
String  value 
)

Sets the private options for the MediaPlayer Kit.

The MediaPlayer Kit supports setting private options by providing key and value. Under normal circumstances, you do not need to know the private option settings, and just use the default option settings.

Note
Calling this method before the open method.
Parameters
keykey.
valuevalue.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setLoopCount()

int io.agora.mediaplayer.AgoraMediaPlayerKit.setLoopCount ( int  loopCount)

Sets the loop playback.

If you want to loop, call this method and set the number of the loops.

When the loop playback ends, the mediaplayer kit returns PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED(6).

Parameters
loopCountThe number of the loops.
Returns
  • 0: Success.
  • < 0: Failure.

◆ switchSrc()

int io.agora.mediaplayer.AgoraMediaPlayerKit.switchSrc ( String  src,
boolean  syncPts 
)

Switches the media resource being played.

You can call this method to switch the media resource to be played according to the current network status. For example, when the network is poor, the media resource to be played is switched to a media resource address with a lower bitrate; when the network is good, the media resource to be played is switched to a media resource address with a higher bitrate.

After calling switchSrc, if you receive the onPlayerEvent callback event PLAYER_EVENT_SWITCH_COMPLETE(9), the switch is successful; if you receive the onPlayerEvent callback event PLAYER_EVENT_SWITCH_ERROR(10), the switch fails.

Note
  • Make sure to call this method after open.
  • To ensure normal playback, pay attention to the following when calling switchSrc(src, true):
    • Do not call this method when playback is paused.
    • Do not call seek during switching.
    • Before switching the media resource, ensure that the playback position does not exceed the total duration of the media resource to be switched.
      Parameters
      srcThe URL address of the media resource to be switched. HTTP, RTMP, and RTSP protocols are supported for local and online media streams.
      syncPtsWhether to synchronize the playback position(millionseconds) before and after the switch:
  • true: (Default) Synchronize the playback position before and after the switch. After the MediaPlayer Kit switches the media resource, it starts playing the media resource from the playback position at the time of the switch. Note: Agora only supports setting syncPts to true when playing on-demand streams.
  • false: The playback position before and after the media resource switch is not synchronized. Instead, the playback position after the media resource is switched is determined as follows:
    • If the media resource is an on-demand stream, the MediaPlayer Kit starts playing the media resource from the beginning.
    • If the media resource is a live stream, the MediaPlayer Kit starts playing the media resource from the playback position when the code rate is switched.

◆ addPreloadSrc()

int io.agora.mediaplayer.AgoraMediaPlayerKit.addPreloadSrc ( String  src,
long  startPos 
)

Preloads media resources.

You can call this method to preload a media resource into the playlist. If you need to preload multiple media resources, you can call this method multiple times.

After calling addPreloadSrc, if you receive the onPreloadEvent callback event PLAYER_PRELOAD_EVENT_COMPLETE(1), the preload is successful; if you receive the onPreloadEvent callback event PLAYER_PRELOAD_EVENT_ERROR(2), the preload fails.

After the preload is successful, if you want to play the media resource, call playPreload; if you want to clear the playlist, call stop.

Note
Agora does not support preloading duplicate media resources to the playlist; however, you can preload the media resources that are being played to the playlist again.
Parameters
srcThe URL address of the preloaded media resource. HTTP, RTMP, and RTSP protocols are supported for local and online media streams.
startPosThe starting position (milliseconds) when starting to play after preloading to the playlist. When preloading a live stream, set startPos to 0.

◆ playPreload()

int io.agora.mediaplayer.AgoraMediaPlayerKit.playPreload ( String  src)

Plays preloaded media resources.

This method only supports playing media resources that have been preloaded into the playlist. After calling this method, if you receive the onPlayerStateChanged callback to report the state PLAYER_STATE_PLAYING, the playback is successful.

If you want to change the preloaded media resource to be played, you can call this method again and specify a new media resource path. If you want to replay the media resource, you need to call addPreloadSrc to preload the media resource to the playlist again before playing. If you want to clear the playlist, call stop.

Note
If you call this method when playback is paused, it does not take effect until playback is resumed.
Parameters
srcThe URL address of the media resource in the playlist. This address must be consistent with the src set by the addPreloadSrc method; otherwise, the media resource cannot be played.

◆ getPlayerSdkVersion()

String io.agora.mediaplayer.AgoraMediaPlayerKit.getPlayerSdkVersion ( )

Gets the version number of the MediaPlayer Kit.

Returns
The version number of the MediaPlayer Kit, such as "1.2.1".