|
IMediaPlayerKit | mediaPlayer = null |
|
◆ AgoraMediaPlayerKit()
io.agora.mediaplayer.AgoraMediaPlayerKit.AgoraMediaPlayerKit |
( |
Context |
context | ) |
|
◆ 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
-
◆ open()
int io.agora.mediaplayer.AgoraMediaPlayerKit.open |
( |
String |
src, |
|
|
long |
startPos |
|
) |
| |
Open the media resource.
- Parameters
-
src | The path of the media resource. Both local path and online path are supported. |
startPos | The 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
-
pos | The new playback position (ms). |
- Returns
-
◆ mute()
int io.agora.mediaplayer.AgoraMediaPlayerKit.mute |
( |
boolean |
mute | ) |
|
Sets whether to mute the media resource.
- Parameters
-
mute | Sets 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
-
volume | The 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
-
videoView | The player's render view. |
- Returns
-
◆ setRenderMode()
int io.agora.mediaplayer.AgoraMediaPlayerKit.setRenderMode |
( |
int |
mode | ) |
|
Sets the player's render mode.
- Parameters
-
mode | The player's render mode
|
- Returns
-
◆ getStreamInfo()
MediaStreamInfo io.agora.mediaplayer.AgoraMediaPlayerKit.getStreamInfo |
( |
int |
index | ) |
|
Gets the detailed information of the media stream.
- Parameters
-
index | The 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 |
( |
| ) |
|
◆ registerPlayerObserver()
void io.agora.mediaplayer.AgoraMediaPlayerKit.registerPlayerObserver |
( |
MediaPlayerObserver |
playerObserver | ) |
|
Registers a player observer.
- Parameters
-
playerObserver | The 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
-
playerObserver | The 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
-
observer | The 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
-
observer | The 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
-
◆ unregisterAudioFrameObserver()
void io.agora.mediaplayer.AgoraMediaPlayerKit.unregisterAudioFrameObserver |
( |
AudioFrameObserver |
observer | ) |
|
Unregisters an audio observer.
- Parameters
-
◆ 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
-
filter | Log 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
-
filePath | The 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
-
index | The 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
-
- 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
-
- 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
-
- 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
-
loopCount | The 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
-
src | The URL address of the media resource to be switched. HTTP, RTMP, and RTSP protocols are supported for local and online media streams. |
syncPts | Whether 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
-
src | The URL address of the preloaded media resource. HTTP, RTMP, and RTSP protocols are supported for local and online media streams. |
startPos | The 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
-
src | The 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"
.