Package io.agora.mediaplayer
Interface IMediaPlayer
public interface IMediaPlayer
-
Method Summary
Modifier and TypeMethodDescriptionintadjustPlayoutVolume(int volume) intadjustPublishSignalVolume(int volume) intdestroy()intenableAutoSwitchAgoraCDN(boolean enable) Deprecated.4.6.0intDeprecated.4.6.0intDeprecated.4.6.0longintGet unique source id of the media player.booleangetMute()intlongGets the current playback position of the media file.Gets the url of the current play media file for publishing.intgetState()intgetStreamInfo(int index) intmute(boolean muted) intopen(Uri uri, long startPos) Opens a media file with a specified URL.intopenWithAgoraCDNSrc(String src, long startPos) Deprecated.4.6.0intopenWithMediaSource(MediaPlayerSource source) Opens a media file with a media file source.intpause()Pauses playing the media file.intplay()Plays the media file.intplayPreloadedSrc(String src) intpreloadSrc(String src, long startPos) intregisterAudioFrameObserver(IMediaPlayerAudioFrameObserver audioFrameObserver, int mode) intregisterMediaPlayerAudioSpectrumObserver(IAudioSpectrumObserver observer, int intervalInMS) Registers the audio frame spectrum observer.intregisterPlayerObserver(IMediaPlayerObserver playerObserver) Registers a media player observer.intregisterVideoFrameObserver(IMediaPlayerVideoFrameObserver videoFrameObserver) intrenewAgoraCDNSrcToken(String token, long ts) Deprecated.4.6.0intresume()Resumes playing the media file.intseek(long newPos) Sets the current playback position of the media file.intselectAudioTrack(int index) Select playback audio track of the media fileintselectInternalSubtitle(int index) select internal subtitles in videointselectMultiAudioTrack(int playoutTrackIndex, int publishTrackIndex) Selects multi audio track of the media file for playback or publish to channel.intsetAudioDualMonoMode(int mode) Set dual-mono output mode of the music file.intsetAudioPitch(int pitch) Sets the pitch of the current media file.intset an external subtitle for videointsetLoopCount(int loopCount) Sets whether to loop the media file for playback.intsetPlaybackSpeed(int speed) Change playback speedintsetPlayerOption(String key, int value) change player option before play a fileintsetPlayerOptionString(String key, String value) change player option before play a fileintsetRenderMode(int mode) intSet spatial audio params for the music file.intsetView(View videoView) intstop()Stops playing the current media file.intswitchAgoraCDNLineByIndex(int index) Deprecated.4.6.0intswitchAgoraCDNSrc(String src, boolean syncPts) Deprecated.4.6.0intinttakeScreenshot(String filename) take screenshot while playing videointUnload a preloaded media sourceintReleases the audio frame spectrum observer.intunRegisterPlayerObserver(IMediaPlayerObserver playerObserver) Releases the media player observer.
-
Method Details
-
getMediaPlayerId
int getMediaPlayerId()Get unique source id of the media player.- Returns:
- - >= 0: The source id of this media player. - < 0: Failure.
-
open
int open(Uri uri, long startPos) Opens a media file with a specified URL.- Parameters:
uri- The uri of the media file that you want to play.- Returns:
- - 0: Success. - < 0: Failure.
-
openWithMediaSource
Opens a media file with a media file source.- Parameters:
source- Media file source that you want to play, see `MediaSource`- Returns:
- - 0: Success. - < 0: Failure.
-
play
int play()Plays the media file.- Returns:
- - 0: Success. - < 0: Failure.
-
pause
int pause()Pauses playing the media file. -
stop
int stop()Stops playing the current media file. -
resume
int resume()Resumes playing the media file. -
seek
int seek(long newPos) Sets the current playback position of the media file.- Parameters:
newPos- The new playback position (ms).- Returns:
- - 0: Success. - < 0: Failure.
-
setAudioPitch
int setAudioPitch(int pitch) Sets the pitch of the current media file.- Parameters:
pitch- Sets 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 mute(boolean muted) - Parameters:
muted- Whether to mute on- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
getMute
boolean getMute()- Returns:
- Whether media player is mute on
-
adjustPlayoutVolume
int adjustPlayoutVolume(int volume) - Parameters:
volume- The 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 MediaPlayerReason
-
getPlayoutVolume
int getPlayoutVolume()- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
getPlayPosition
long getPlayPosition()Gets the current playback position of the media file.- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
getDuration
long getDuration()- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
getState
Constants.MediaPlayerState getState()- Returns:
- MediaPlayerState
-
getStreamCount
int getStreamCount()- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
setView
int setView(View videoView) - Parameters:
videoView- view object, windows platform is HWND- Returns:
- int <= 0 On behalf of an error, the value corresponds to one of MediaPlayerReason
-
setRenderMode
int setRenderMode(int mode) - Parameters:
mode- Video display mode- Returns:
- int < 0 on behalf of an error, the value corresponds to one of MediaPlayerReason
-
getStreamInfo
-
setLoopCount
int setLoopCount(int loopCount) Sets whether to loop the media file for playback.- Parameters:
loopCount- the 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 setPlaybackSpeed(int speed) Change playback speed- Parameters:
speed- the enum of playback speed- Returns:
- - 0: Success. - < 0: Failure.
-
selectAudioTrack
int selectAudioTrack(int index) Select playback audio track of the media file- Parameters:
index- the index of the audio track in media file- Returns:
- - 0: Success. - < 0: Failure.
-
selectMultiAudioTrack
int selectMultiAudioTrack(int playoutTrackIndex, int publishTrackIndex) Selects multi audio track of the media file for playback or publish to channel.- Parameters:
playoutTrackIndex- The index of the audio track in media file for local playback.publishTrackIndex- The index of the audio track in the media file published to the remote.- Returns:
- - 0: Success. - < 0: Failure. See {@link media::base::MEDIA_PLAYER_REASON MEDIA_PLAYER_REASON}. - -2: Invalid argument. Argument must be greater than or equal to zero. - -8: Invalid State.You must open the media file with openWithMediaSource and set enableMultiAudioTrack to true
-
setPlayerOption
change player option before play a file- Parameters:
key- the key of the option paramvalue- the value of option param- Returns:
- - 0: Success. - < 0: Failure.
-
setPlayerOptionString
change player option before play a file- Parameters:
key- the key of the option paramvalue- the value of option param- Returns:
- - 0: Success. - < 0: Failure.
-
takeScreenshot
take screenshot while playing video- Parameters:
filename- the filename of screenshot file- Returns:
- - 0: Success. - < 0: Failure.
-
selectInternalSubtitle
int selectInternalSubtitle(int index) select internal subtitles in video- Parameters:
index- the index of the internal subtitles- Returns:
- - 0: Success. - < 0: Failure.
-
setExternalSubtitle
set an external subtitle for video- Parameters:
url- The URL of the subtitle file that you want to load.- Returns:
- - 0: Success. - < 0: Failure.
-
adjustPublishSignalVolume
int adjustPublishSignalVolume(int volume) - Returns:
- int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
-
getPublishSignalVolume
int getPublishSignalVolume()- Returns:
- int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
-
getPlaySrc
String getPlaySrc()Gets the url of the current play media file for publishing.- Returns:
- the current play media file for publishing.
-
switchSrc
- Parameters:
src- The URL of the sourcesyncPts- whether to sync pts for the other source- Returns:
- int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
-
preloadSrc
- Parameters:
src- The URL of the sourcestartPos- play pos of the preload source- Returns:
- int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
-
playPreloadedSrc
- Parameters:
src- The URL of the source- Returns:
- int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
-
unloadSrc
Unload a preloaded media source- Parameters:
src- Specific src.- Returns:
- - 0: Success. - < 0: Failure.
-
destroy
int destroy()- Returns:
- - 0: Success. - < 0: Failure.
-
registerPlayerObserver
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:
playerObserver- The pointer to the IMediaPlayerObserver object.- Returns:
- - 0: Success. - < 0: Failure.
-
unRegisterPlayerObserver
Releases the media player observer.- Parameters:
playerObserver- The pointer to the IMediaPlayerObserver object.- Returns:
- - 0: Success. - < 0: Failure.
-
registerAudioFrameObserver
-
registerMediaPlayerAudioSpectrumObserver
Registers the audio frame spectrum observer.- Parameters:
observer- The pointer to the {@link media::base::IAudioSpectrumObserver IAudioSpectrumObserver} object.- Returns:
- - 0: Success. - < 0: Failure.
-
unregisterMediaPlayerAudioSpectrumObserver
Releases the audio frame spectrum observer.- Parameters:
observer- The pointer to the {@link media::base::IAudioSpectrumObserver IAudioSpectrumObserver} object.- Returns:
- - 0: Success. - < 0: Failure.
-
setAudioDualMonoMode
int setAudioDualMonoMode(int mode) Set dual-mono output mode of the music file.- Parameters:
mode- SeeAudioDualMonoMode. Default in AUDIO_DUAL_MONO_STEREO- Returns:
- - 0: Success. - < 0: Failure.
-
registerVideoFrameObserver
-
openWithAgoraCDNSrc
Deprecated.4.6.0Open the Agora CDN media source.- Parameters:
src- The src of the media file that you want to play.startPos- The playback position (ms).- Returns:
- - 0: Success. - < 0: Failure.
-
getAgoraCDNLineCount
Deprecated.4.6.0Gets the number of Agora CDN lines.- Returns:
- - > 0: number of CDN. - <= 0: Failure.
-
switchAgoraCDNLineByIndex
Deprecated.4.6.0Switch Agora CDN lines.- Parameters:
index- Specific CDN line index.- Returns:
- - 0: Success. - < 0: Failure.
-
getCurrentAgoraCDNIndex
Deprecated.4.6.0Gets the line of the current CDN.- Returns:
- - >= 0: Specific line. - < 0: Failure.
-
enableAutoSwitchAgoraCDN
Deprecated.4.6.0Enable automatic CDN line switching.- Parameters:
enable- Whether enable.- Returns:
- - 0: Success. - < 0: Failure.
-
renewAgoraCDNSrcToken
Deprecated.4.6.0Update the CDN source token and timestamp.- Parameters:
token- token.ts- ts.- Returns:
- - 0: Success. - < 0: Failure.
-
switchAgoraCDNSrc
Deprecated.4.6.0Switch the CDN source.- Parameters:
src- Specific src.syncPts- Live streaming must be set to false.- Returns:
- - 0: Success. - < 0: Failure.
-
setSpatialAudioParams
Set spatial audio params for the music file. It can be called after the media player was created.- Parameters:
params- SeeSpatialAudioParams. If it's not set, then the spatial audio will be disabled; or it will be enabled.- Returns:
- - 0: Success. - < 0: Failure.
-