Agora Java API Reference for Android
Public Member Functions | List of all members
io.agora.mediaplayer.IMediaPlayer Interface Reference

Public Member Functions

int getMediaPlayerId ()
 
int open (Uri uri, long startPos)
 
int open (String url, long startPos)
 
int openWithCustomSource (long startPos, IMediaPlayerCustomDataProvider provider)
 
int openWithMediaSource (MediaPlayerSource source)
 
int play ()
 
int pause ()
 
int stop ()
 
int resume ()
 
int seek (long newPos)
 
int setAudioPitch (int pitch)
 
int mute (boolean mute)
 Turn mute on or off. More...
 
boolean isMuted ()
 Get mute state. More...
 
int adjustPlayoutVolume (int volume)
 Adjust playback volume. More...
 
int getPlayoutVolume ()
 Get the current playback volume. More...
 
long getPlayPosition ()
 
long getDuration ()
 Get media duration. More...
 
Constants.MediaPlayerState getState ()
 Get player state. More...
 
int getStreamCount ()
 Get the number of streams in the media. More...
 
int setView (View videoView)
 Set video rendering view. More...
 
int setRenderMode (int mode)
 Set video display mode. More...
 
MediaStreamInfo getStreamInfo (int index)
 
int setLoopCount (int loopCount)
 
int setPlaybackSpeed (int speed)
 
int selectAudioTrack (int index)
 
int setPlayerOption (String key, int value)
 
int setPlayerOptionString (String key, String value)
 
int takeScreenshot (String filename)
 
int selectInternalSubtitle (int index)
 
int setExternalSubtitle (String url)
 
int adjustPublishSignalVolume (int volume)
 adjust publish signal volume More...
 
int getPublishSignalVolume ()
 get publish signal volume More...
 
String getPlaySrc ()
 
int switchSrc (String src, boolean syncPts)
 switch to another play source More...
 
int preloadSrc (String src, long startPos)
 preload another play source More...
 
int playPreloadedSrc (String src)
 play the preloaded source More...
 
int unloadSrc (String src)
 
int destroy ()
 
int registerPlayerObserver (IMediaPlayerObserver playerObserver)
 
int unRegisterPlayerObserver (IMediaPlayerObserver playerObserver)
 
int registerAudioFrameObserver (IMediaPlayerAudioFrameObserver audioFrameObserver, int mode)
 
int registerMediaPlayerAudioSpectrumObserver (IAudioSpectrumObserver observer, int intervalInMS)
 
int unregisterMediaPlayerAudioSpectrumObserver (IAudioSpectrumObserver observer)
 
int setAudioDualMonoMode (int mode)
 
int registerVideoFrameObserver (IMediaPlayerVideoFrameObserver videoFrameObserver)
 
int openWithAgoraCDNSrc (String src, long startPos)
 
int getAgoraCDNLineCount ()
 
int switchAgoraCDNLineByIndex (int index)
 
int getCurrentAgoraCDNIndex ()
 
int enableAutoSwitchAgoraCDN (boolean enable)
 
int renewAgoraCDNSrcToken (String token, long ts)
 
int switchAgoraCDNSrc (String src, boolean syncPts)
 
int setSpatialAudioParams (SpatialAudioParams params)
 

Member Function Documentation

◆ getMediaPlayerId()

int io.agora.mediaplayer.IMediaPlayer.getMediaPlayerId ( )

Get unique source id of the media player.

Returns
  • >= 0: The source id of this media player.
  • < 0: Failure.

◆ open() [1/2]

int io.agora.mediaplayer.IMediaPlayer.open ( Uri  uri,
long  startPos 
)

Opens a media file with a specified URL.

Parameters
uriThe uri of the media file that you want to play.
Returns
  • 0: Success.
  • < 0: Failure.

◆ open() [2/2]

int io.agora.mediaplayer.IMediaPlayer.open ( String  url,
long  startPos 
)

Opens a media file with a andorid URI.

Parameters
urlThe URL of the media file that you want to play.
Returns
  • 0: Success.
  • < 0: Failure.

◆ openWithCustomSource()

int io.agora.mediaplayer.IMediaPlayer.openWithCustomSource ( long  startPos,
IMediaPlayerCustomDataProvider  provider 
)
Deprecated:
Opens a media with custom data provider
Parameters
startPosthe start position
providercustom data provider
Returns
  • 0: Success.
  • < 0: Failure.

◆ openWithMediaSource()

int io.agora.mediaplayer.IMediaPlayer.openWithMediaSource ( MediaPlayerSource  source)

Opens a media file with a media file source.

Parameters
sourceMedia file source that you want to play, see MediaSource
Returns
  • 0: Success.
  • < 0: Failure.

◆ play()

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

Plays the media file.

Returns
  • 0: Success.
  • < 0: Failure.

◆ pause()

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

Pauses playing the media file.

◆ stop()

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

Stops playing the current media file.

◆ resume()

int io.agora.mediaplayer.IMediaPlayer.resume ( )

Resumes playing the media file.

◆ seek()

int io.agora.mediaplayer.IMediaPlayer.seek ( long  newPos)

Sets the current playback position of the media file.

Parameters
newPosThe new playback position (ms).
Returns
  • 0: Success.
  • < 0: Failure.

◆ setAudioPitch()

int io.agora.mediaplayer.IMediaPlayer.setAudioPitch ( int  pitch)

Sets the pitch of the current media file.

Parameters
pitchSets the pitch of the local music file by chromatic scale. The default value is 0, which means keeping the original pitch. The value ranges from -12 to 12, and the pitch value between consecutive values is a chromatic value. The greater the absolute value of this parameter, the higher or lower the pitch of the local music file.
Returns
  • 0: Success.
  • < 0: Failure.

◆ mute()

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

Turn mute on or off.

Parameters
muteWhether to mute on
Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError

◆ isMuted()

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

Get mute state.

Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError
Parameters
[out]muteWhether is mute on

◆ adjustPlayoutVolume()

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

Adjust playback volume.

Parameters
volumeThe volume value to be adjusted The volume can be adjusted from 0 to 400: 0: mute; 100: original volume; 400: Up to 4 times the original volume (with built-in overflow protection).
Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError

◆ getPlayoutVolume()

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

Get the current playback volume.

Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError
Parameters
[out]volume

◆ getPlayPosition()

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

Gets the current playback position of the media file.

Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError

◆ getDuration()

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

Get media duration.

Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError
Parameters
[out]durationDuration in seconds

◆ getState()

Constants.MediaPlayerState io.agora.mediaplayer.IMediaPlayer.getState ( )

Get player state.

Returns
MediaPlayerState

◆ getStreamCount()

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

Get the number of streams in the media.

Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError
Parameters
[out]count

◆ setView()

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

Set video rendering view.

Parameters
videoViewview object, windows platform is HWND
Returns
int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerError

◆ setRenderMode()

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

Set video display mode.

Parameters
modeVideo display mode
Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ setLoopCount()

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

Sets whether to loop the media file for playback.

Parameters
loopCountthe number of times looping the media file.
  • 0: Play the audio effect once.
  • 1: Play the audio effect twice.
  • -1: Play the audio effect in a loop indefinitely, until stopEffect() or stop() is called.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setPlaybackSpeed()

int io.agora.mediaplayer.IMediaPlayer.setPlaybackSpeed ( int  speed)

Change playback speed

Parameters
speedthe enum of playback speed
Returns
  • 0: Success.
  • < 0: Failure.

◆ selectAudioTrack()

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

Select playback audio track of the media file

Parameters
indexthe index of the audio track in media file
Returns
  • 0: Success.
  • < 0: Failure.

◆ setPlayerOption()

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

change player option before play a file

Parameters
keythe key of the option param
valuethe value of option param
Returns
  • 0: Success.
  • < 0: Failure.

◆ setPlayerOptionString()

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

change player option before play a file

Parameters
keythe key of the option param
valuethe value of option param
Returns
  • 0: Success.
  • < 0: Failure.

◆ takeScreenshot()

int io.agora.mediaplayer.IMediaPlayer.takeScreenshot ( String  filename)

take screenshot while playing video

Parameters
filenamethe filename of screenshot file
Returns
  • 0: Success.
  • < 0: Failure.

◆ selectInternalSubtitle()

int io.agora.mediaplayer.IMediaPlayer.selectInternalSubtitle ( int  index)

select internal subtitles in video

Parameters
indexthe index of the internal subtitles
Returns
  • 0: Success.
  • < 0: Failure.

◆ setExternalSubtitle()

int io.agora.mediaplayer.IMediaPlayer.setExternalSubtitle ( String  url)

set an external subtitle for video

Parameters
urlThe URL of the subtitle file that you want to load.
Returns
  • 0: Success.
  • < 0: Failure.

◆ adjustPublishSignalVolume()

int io.agora.mediaplayer.IMediaPlayer.adjustPublishSignalVolume ( int  volume)

adjust publish signal volume

Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ getPublishSignalVolume()

int io.agora.mediaplayer.IMediaPlayer.getPublishSignalVolume ( )

get publish signal volume

Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ getPlaySrc()

String io.agora.mediaplayer.IMediaPlayer.getPlaySrc ( )

Gets the url of the current play media file for publishing.

Returns
the current play media file for publishing.

◆ switchSrc()

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

switch to another play source

Parameters
srcThe URL of the source
syncPtswhether to sync pts for the other source
Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ preloadSrc()

int io.agora.mediaplayer.IMediaPlayer.preloadSrc ( String  src,
long  startPos 
)

preload another play source

Parameters
srcThe URL of the source
startPosplay pos of the preload source
Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ playPreloadedSrc()

int io.agora.mediaplayer.IMediaPlayer.playPreloadedSrc ( String  src)

play the preloaded source

Parameters
srcThe URL of the source
Returns
int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_ERROR

◆ unloadSrc()

int io.agora.mediaplayer.IMediaPlayer.unloadSrc ( String  src)

Unload a preloaded media source

Parameters
srcSpecific src.
Returns
  • 0: Success.
  • < 0: Failure.

◆ destroy()

int io.agora.mediaplayer.IMediaPlayer.destroy ( )
Returns
  • 0: Success.
  • < 0: Failure.

◆ registerPlayerObserver()

int io.agora.mediaplayer.IMediaPlayer.registerPlayerObserver ( IMediaPlayerObserver  playerObserver)

Registers a media player observer.

Once the media player observer is registered, you can use the observer to monitor the state change of the media player.

Parameters
playerObserverThe pointer to the IMediaPlayerObserver object.
Returns
  • 0: Success.
  • < 0: Failure.

◆ unRegisterPlayerObserver()

int io.agora.mediaplayer.IMediaPlayer.unRegisterPlayerObserver ( IMediaPlayerObserver  playerObserver)

Releases the media player observer.

Parameters
playerObserverThe pointer to the IMediaPlayerObserver object.
Returns
  • 0: Success.
  • < 0: Failure.

◆ registerMediaPlayerAudioSpectrumObserver()

int io.agora.mediaplayer.IMediaPlayer.registerMediaPlayerAudioSpectrumObserver ( IAudioSpectrumObserver  observer,
int  intervalInMS 
)

Registers the audio frame spectrum observer.

Parameters
observerThe pointer to the IAudioSpectrumObserver object.
Returns
  • 0: Success.
  • < 0: Failure.

◆ unregisterMediaPlayerAudioSpectrumObserver()

int io.agora.mediaplayer.IMediaPlayer.unregisterMediaPlayerAudioSpectrumObserver ( IAudioSpectrumObserver  observer)

Releases the audio frame spectrum observer.

Parameters
observerThe pointer to the IAudioSpectrumObserver object.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setAudioDualMonoMode()

int io.agora.mediaplayer.IMediaPlayer.setAudioDualMonoMode ( int  mode)

Set dual-mono output mode of the music file.

Parameters
modeSee AudioDualMonoMode. Default in AUDIO_DUAL_MONO_STEREO
Returns
  • 0: Success.
  • < 0: Failure.

◆ openWithAgoraCDNSrc()

int io.agora.mediaplayer.IMediaPlayer.openWithAgoraCDNSrc ( String  src,
long  startPos 
)

Open the Agora CDN media source.

Parameters
srcThe src of the media file that you want to play.
startPosThe playback position (ms).
Returns
  • 0: Success.
  • < 0: Failure.

◆ getAgoraCDNLineCount()

int io.agora.mediaplayer.IMediaPlayer.getAgoraCDNLineCount ( )

Gets the number of Agora CDN lines.

Returns
  • > 0: number of CDN.
  • <= 0: Failure.

◆ switchAgoraCDNLineByIndex()

int io.agora.mediaplayer.IMediaPlayer.switchAgoraCDNLineByIndex ( int  index)

Switch Agora CDN lines.

Parameters
indexSpecific CDN line index.
Returns
  • 0: Success.
  • < 0: Failure.

◆ getCurrentAgoraCDNIndex()

int io.agora.mediaplayer.IMediaPlayer.getCurrentAgoraCDNIndex ( )

Gets the line of the current CDN.

Returns
  • >= 0: Specific line.
  • < 0: Failure.

◆ enableAutoSwitchAgoraCDN()

int io.agora.mediaplayer.IMediaPlayer.enableAutoSwitchAgoraCDN ( boolean  enable)

Enable automatic CDN line switching.

Parameters
enableWhether enable.
Returns
  • 0: Success.
  • < 0: Failure.

◆ renewAgoraCDNSrcToken()

int io.agora.mediaplayer.IMediaPlayer.renewAgoraCDNSrcToken ( String  token,
long  ts 
)

Update the CDN source token and timestamp.

Parameters
tokentoken.
tsts.
Returns
  • 0: Success.
  • < 0: Failure.

◆ switchAgoraCDNSrc()

int io.agora.mediaplayer.IMediaPlayer.switchAgoraCDNSrc ( String  src,
boolean  syncPts 
)

Switch the CDN source.

Parameters
srcSpecific src.
syncPtsLive streaming must be set to false.
Returns
  • 0: Success.
  • < 0: Failure.

◆ setSpatialAudioParams()

int io.agora.mediaplayer.IMediaPlayer.setSpatialAudioParams ( SpatialAudioParams  params)

Set spatial audio params for the music file. It can be called after the media player was created.

Parameters
paramsSee SpatialAudioParams. If it's not set, then the spatial audio will be disabled; or it will be enabled.
Returns
  • 0: Success.
  • < 0: Failure.