|
Agora Java API Reference for Android
|
Public Member Functions | |
| int | getMediaPlayerId () |
| Gets the ID of the media player. More... | |
| int | open (Uri uri, long startPos) |
| Opens a media file through a URI address. More... | |
| int | open (String url, long startPos) |
| Opens the media resource. More... | |
| int | openWithMediaSource (MediaPlayerSource source) |
| Opens a media file and configures the playback scenarios. More... | |
| int | play () |
| Plays the media file. More... | |
| int | pause () |
| Pauses the playback. More... | |
| int | stop () |
| Stops playing the media track. More... | |
| int | resume () |
| Resumes playing the media file. More... | |
| int | seek (long newPos) |
| Seeks to a new playback position. More... | |
| int | setAudioPitch (int pitch) |
| Sets the pitch of the current media resource. More... | |
| int | mute (boolean muted) |
| Sets whether to mute the media file. More... | |
| boolean | getMute () |
| Reports whether the media resource is muted. More... | |
| int | adjustPlayoutVolume (int volume) |
| Adjusts the local playback volume. More... | |
| int | getPlayoutVolume () |
| Gets the local playback volume. More... | |
| long | getPlayPosition () |
| Gets current local playback progress. More... | |
| long | getDuration () |
| Gets the duration of the media resource. More... | |
| int | getAudioBufferDelay () |
| Gets the audio buffer delay when playing the media file. More... | |
| Constants.MediaPlayerState | getState () |
| Gets current playback state. More... | |
| int | getStreamCount () |
| Gets the number of the media streams in the media resource. More... | |
| int | setView (View videoView) |
| Sets the view. More... | |
| int | setRenderMode (int mode) |
| Sets the render mode of the media player. More... | |
| MediaStreamInfo | getStreamInfo (int index) |
| Gets the detailed information of the media stream. More... | |
| int | setLoopCount (int loopCount) |
| Sets the loop playback. More... | |
| int | setPlaybackSpeed (int speed) |
| Sets the channel mode of the current audio file. More... | |
| int | selectAudioTrack (int index) |
| Selects the audio track used during playback. More... | |
| int | selectMultiAudioTrack (int playoutTrackIndex, int publishTrackIndex) |
| Selects the audio tracks that you want to play on your local device and publish to the channel respectively. More... | |
| int | setPlayerOption (String key, int value) |
| Sets media player options. More... | |
| int | setPlayerOptionString (String key, String value) |
| Sets media player options. More... | |
| int | takeScreenshot (String filename) |
| int | selectInternalSubtitle (int index) |
| int | setExternalSubtitle (String url) |
| int | adjustPublishSignalVolume (int volume) |
| Adjusts the volume of the media file for publishing. More... | |
| int | getPublishSignalVolume () |
| Gets the volume of the media file for publishing. More... | |
| String | getPlaySrc () |
| Gets the path of the media resource being played. More... | |
| int | switchSrc (String src, boolean syncPts) |
| Switches the media resource being played. More... | |
| int | preloadSrc (String src, long startPos) |
| Preloads a media resource. More... | |
| int | playPreloadedSrc (String src) |
| Plays preloaded media resources. More... | |
| int | unloadSrc (String src) |
| Unloads media resources that are preloaded. More... | |
| int | destroy () |
| Destroys the media player instance. More... | |
| int | registerPlayerObserver (IMediaPlayerObserver playerObserver) |
| Registers a media player observer. More... | |
| int | unRegisterPlayerObserver (IMediaPlayerObserver playerObserver) |
| Releases a media player observer. More... | |
| int | registerAudioFrameObserver (IMediaPlayerAudioFrameObserver audioFrameObserver, int mode) |
| Registers an audio frame observer object. More... | |
| int | registerMediaPlayerAudioSpectrumObserver (IAudioSpectrumObserver observer, int intervalInMS) |
| int | unregisterMediaPlayerAudioSpectrumObserver (IAudioSpectrumObserver observer) |
| int | setAudioDualMonoMode (int mode) |
| Sets the channel mode of the current audio file. More... | |
| int | registerVideoFrameObserver (IMediaPlayerVideoFrameObserver videoFrameObserver) |
| Registers a video frame observer object. More... | |
| 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) |
| Enables or disables the spatial audio effect for the media player. More... | |
| int io.agora.mediaplayer.IMediaPlayer.getMediaPlayerId | ( | ) |
Gets the ID of the media player.
| int io.agora.mediaplayer.IMediaPlayer.open | ( | Uri | uri, |
| long | startPos | ||
| ) |
Opens a media file through a URI address.
| uri | The URI (Uniform Resource Identifier) of the media file. |
| startPos | The starting position (ms) for playback. The default value is 0. |
| int io.agora.mediaplayer.IMediaPlayer.open | ( | String | url, |
| long | startPos | ||
| ) |
Opens the media resource.
This method supports playing URI files starting with content://. Call timing: This method can be called either before or after joining the channel. Related callbacks: After calling this method, the SDK triggers the onPlayerStateChanged callback. After receiving the report of the playback status as PLAYER_STATE_OPEN_COMPLETED, you can call the play method to play the media file.
| url | The path of the media file. Both local path and online path are supported. |
| startPos | The starting position (ms) for playback. Default value is 0. |
Implemented in io.agora.musiccontentcenter.IAgoraMusicPlayer.
| int io.agora.mediaplayer.IMediaPlayer.openWithMediaSource | ( | MediaPlayerSource | source | ) |
Opens a media file and configures the playback scenarios.
This method supports opening different types of media files, including URI files starting with content://, media files in the assets folder, and setting the playback options. Call timing: You can call this method either before or after joining a channel.
onPlayerStateChanged callback reporting PLAYER_STATE_OPEN_COMPLETED before calling the play method to play the file.| source | Media resources. See MediaPlayerSource. |
| int io.agora.mediaplayer.IMediaPlayer.play | ( | ) |
Plays the media file.
Call timing: - Call this method after calling open(String url, long startPos) or openWithMediaSource opening a media file and receiving a onPlayerStateChanged callback reporting the status as PLAYER_STATE_OPEN_COMPLETED.
seek.| int io.agora.mediaplayer.IMediaPlayer.pause | ( | ) |
Pauses the playback.
Call timing: You can call this method either before or after joining a channel.
| int io.agora.mediaplayer.IMediaPlayer.stop | ( | ) |
Stops playing the media track.
After calling this method to stop playback, if you want to play again, you need to call open(String url, long startPos) or openWithMediaSource to open the media resource. Call timing: Call this method after play.
Implemented in io.agora.musiccontentcenter.IAgoraMusicPlayer.
| int io.agora.mediaplayer.IMediaPlayer.resume | ( | ) |
Resumes playing the media file.
| int io.agora.mediaplayer.IMediaPlayer.seek | ( | long | newPos | ) |
Seeks to a new playback position.
seek after the playback has completed (upon receiving callback onPlayerStateChanged reporting playback status as PLAYER_STATE_PLAYBACK_COMPLETED or PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED ), the SDK will play the media file from the specified position. At this point, you will receive callback onPlayerStateChanged reporting playback status as PLAYER_STATE_PLAYING.seek while the playback is paused, upon successful call of this method, the SDK will seek to the specified position. To resume playback, call resume or play . Call timing: You can call this method either before or after joining a channel. Related callbacks: After successfully calling this method, you will receive the onPlayerEvent callback, reporting the result of the seek operation to the new playback position.| newPos | The new playback position (ms). |
| int io.agora.mediaplayer.IMediaPlayer.setAudioPitch | ( | int | pitch | ) |
Sets the pitch of the current media resource.
open(String url, long startPos).| pitch | Sets the pitch of the local music file by the 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. |
| int io.agora.mediaplayer.IMediaPlayer.mute | ( | boolean | muted | ) |
Sets whether to mute the media file.
Call timing: You can call this method either before or after joining a channel.
| muted | Whether to mute the media file:
|
| boolean io.agora.mediaplayer.IMediaPlayer.getMute | ( | ) |
Reports whether the media resource is muted.
true: Reports whether the media resource is muted.false: Reports whether the media resource is muted. | int io.agora.mediaplayer.IMediaPlayer.adjustPlayoutVolume | ( | int | volume | ) |
Adjusts the local playback volume.
Call timing: This method can be called either before or after joining the channel.
| volume | The local playback volume, which ranges from 0 to 100:
|
| int io.agora.mediaplayer.IMediaPlayer.getPlayoutVolume | ( | ) |
Gets the local playback volume.
| long io.agora.mediaplayer.IMediaPlayer.getPlayPosition | ( | ) |
Gets current local playback progress.
MediaPlayerReason. | long io.agora.mediaplayer.IMediaPlayer.getDuration | ( | ) |
Gets the duration of the media resource.
| int io.agora.mediaplayer.IMediaPlayer.getAudioBufferDelay | ( | ) |
Gets the audio buffer delay when playing the media file.
| Constants.MediaPlayerState io.agora.mediaplayer.IMediaPlayer.getState | ( | ) |
Gets current playback state.
MediaPlayerState. | int io.agora.mediaplayer.IMediaPlayer.getStreamCount | ( | ) |
Gets the number of the media streams in the media resource.
open(String url, long startPos) and receive the onPlayerStateChanged callback reporting the state PLAYER_STATE_OPEN_COMPLETED.MediaPlayerReason. | int io.agora.mediaplayer.IMediaPlayer.setView | ( | View | videoView | ) |
Sets the view.
Call timing: You can call this method either before or after joining a channel.
| videoView | The render view. |
| int io.agora.mediaplayer.IMediaPlayer.setRenderMode | ( | int | mode | ) |
Sets the render mode of the media player.
| mode | Sets the render mode of the view:
|
| MediaStreamInfo io.agora.mediaplayer.IMediaPlayer.getStreamInfo | ( | int | index | ) |
Gets the detailed information of the media stream.
Call timing: Call this method after calling getStreamCount.
| index | The index of the media stream. This parameter must be less than the return value of getStreamCount. |
MediaStreamInfo.NULL is returned, if the method call fails. | int io.agora.mediaplayer.IMediaPlayer.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 finishes, the SDK triggers onPlayerStateChanged and reports the playback state as PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED.
| loopCount | The number of times the audio effect loops:
|
| int io.agora.mediaplayer.IMediaPlayer.setPlaybackSpeed | ( | int | speed | ) |
Sets the channel mode of the current audio file.
Call this method after calling open(String url, long startPos).
| speed | The playback speed. Agora recommends that you set this to a value between 30 and 400, defined as follows:
|
| int io.agora.mediaplayer.IMediaPlayer.selectAudioTrack | ( | int | index | ) |
Selects the audio track used during playback.
After getting the track index of the audio file, you can call this method to specify any track to play. For example, if different tracks of a multi-track file store songs in different languages, you can call this method to set the playback language.
getStreamInfo to get the audio stream index value.| index | The index of the audio track. |
| int io.agora.mediaplayer.IMediaPlayer.selectMultiAudioTrack | ( | int | playoutTrackIndex, |
| int | publishTrackIndex | ||
| ) |
Selects the audio tracks that you want to play on your local device and publish to the channel respectively.
You can call this method to determine the audio track to be played on your local device and published to the channel. Before calling this method, you need to open the media file with the openWithMediaSource method and set enableMultiAudioTrack in MediaPlayerSource as true. Applicable scenarios: For example, in KTV scenarios, the host can choose to play the original sound locally and publish the accompaniment track to the channel.
| playoutTrackIndex | The index of audio tracks for local playback. You can obtain the index through getStreamInfo. |
| publishTrackIndex | The index of audio tracks to be published in the channel. You can obtain the index through getStreamInfo. |
| int io.agora.mediaplayer.IMediaPlayer.setPlayerOption | ( | String | key, |
| int | value | ||
| ) |
Sets media player options.
The media player supports setting options through key and value. The difference between this method and setPlayerOptionString is that the value parameter of this method is of type Int, while the value of setPlayerOptionString is of type String. These two methods cannot be used together. Applicable scenarios: Scenarios that require technical previews or special customization features. In general, you do not need to call this method; you can simply use the default options provided by the media player. Call timing: Call this method before the open(String url, long startPos) or openWithMediaSource method.
| key | The key of the option. |
| value | The value of the key. |
| int io.agora.mediaplayer.IMediaPlayer.setPlayerOptionString | ( | String | key, |
| String | value | ||
| ) |
Sets media player options.
The media player supports setting options through key and value. The difference between this method and setPlayerOption is that the value parameter of this method is of type String, while the value of setPlayerOption is of type String. These two methods cannot be used together. Applicable scenarios: Scenarios that require technical previews or special customization features. In general, you do not need to call this method; you can simply use the default options provided by the media player. Call timing: Call this method before the open(String url, long startPos) or openWithMediaSource method.
| key | The key of the option. |
| value | The value of the key. |
| int io.agora.mediaplayer.IMediaPlayer.takeScreenshot | ( | String | filename | ) |
take screenshot while playing video
| filename | the filename of screenshot file |
| int io.agora.mediaplayer.IMediaPlayer.selectInternalSubtitle | ( | int | index | ) |
select internal subtitles in video
| index | the index of the internal subtitles |
| int io.agora.mediaplayer.IMediaPlayer.setExternalSubtitle | ( | String | url | ) |
set an external subtitle for video
| url | The URL of the subtitle file that you want to load. |
| int io.agora.mediaplayer.IMediaPlayer.adjustPublishSignalVolume | ( | int | volume | ) |
Adjusts the volume of the media file for publishing.
After connected to the Agora server, you can call this method to adjust the volume of the media file heard by the remote user. Call timing: This method can be called either before or after joining the channel.
| volume | The volume, which ranges from 0 to 400:
|
| int io.agora.mediaplayer.IMediaPlayer.getPublishSignalVolume | ( | ) |
Gets the volume of the media file for publishing.
| String io.agora.mediaplayer.IMediaPlayer.getPlaySrc | ( | ) |
Gets the path of the media resource being played.
Implemented in io.agora.musiccontentcenter.IAgoraMusicPlayer.
| int io.agora.mediaplayer.IMediaPlayer.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:
onPlayerEvent callback report the PLAYER_EVENT_SWITCH_COMPLETE event, the switching is successful. If the switching fails, the SDK will automatically retry 3 times. If it still fails, you will receive the onPlayerEvent callback reporting the PLAYER_EVENT_SWITCH_ERROR event indicating an error occurred during media resource switching.open(String url, long startPos).seek method during switching.| src | The URL of the media resource. |
| syncPts | Whether to synchronize the playback position (ms) before and after the switch:
|
| int io.agora.mediaplayer.IMediaPlayer.preloadSrc | ( | String | src, |
| long | startPos | ||
| ) |
Preloads a media resource.
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 this method, if you receive the PLAYER_PRELOAD_EVENT_COMPLETE event in the onPreloadEvent callback, the preload is successful; If you receive the PLAYER_PRELOAD_EVENT_ERROR event in the onPreloadEvent callback, the preload fails. If the preload is successful and you want to play the media resource, call playPreloadedSrc; if you want to clear the playlist, call stop().
open(String url, long startPos) or openWithMediaSource to open the media resource successfully.| src | The URL of the media resource. |
| startPos | The starting position (ms) for playing after the media resource is preloaded to the playlist. When preloading a live stream, set this parameter to 0. |
| int io.agora.mediaplayer.IMediaPlayer.playPreloadedSrc | ( | String | src | ) |
Plays preloaded media resources.
After calling the preloadSrc method to preload the media resource into the playlist, you can call this method to play the preloaded media resource. After calling this method, if you receive the onPlayerStateChanged callback which reports the PLAYER_STATE_PLAYING state, the playback is successful. If you want to change the preloaded media resource to be played, you can call this method again and specify the URL of the new media resource that you want to preload. If you want to replay the media resource, you need to call preloadSrc to preload the media resource to the playlist again before playing. If you want to clear the playlist, call the stop() method.
| src | The URL of the media resource in the playlist must be consistent with the src set by the preloadSrc method; otherwise, the media resource cannot be played. |
| int io.agora.mediaplayer.IMediaPlayer.unloadSrc | ( | String | src | ) |
Unloads media resources that are preloaded.
| src | The URL of the media resource. |
| int io.agora.mediaplayer.IMediaPlayer.destroy | ( | ) |
Destroys the media player instance.
Implemented in io.agora.musiccontentcenter.IAgoraMusicPlayer.
| int io.agora.mediaplayer.IMediaPlayer.registerPlayerObserver | ( | IMediaPlayerObserver | playerObserver | ) |
Registers a media player observer.
Call timing: This method can be called either before or after joining the channel.
| playerObserver | The player observer, listening for events during the playback. See IMediaPlayerObserver. |
| int io.agora.mediaplayer.IMediaPlayer.unRegisterPlayerObserver | ( | IMediaPlayerObserver | playerObserver | ) |
Releases a media player observer.
| playerObserver | The player observer, listening for events during the playback. See IMediaPlayerObserver. |
| int io.agora.mediaplayer.IMediaPlayer.registerAudioFrameObserver | ( | IMediaPlayerAudioFrameObserver | audioFrameObserver, |
| int | mode | ||
| ) |
Registers an audio frame observer object.
| audioFrameObserver | The audio frame observer, reporting the reception of each audio frame. See IMediaPlayerAudioFrameObserver. |
| mode | The use mode of the audio frame:
|
| int io.agora.mediaplayer.IMediaPlayer.registerMediaPlayerAudioSpectrumObserver | ( | IAudioSpectrumObserver | observer, |
| int | intervalInMS | ||
| ) |
Registers the audio frame spectrum observer.
| observer | The pointer to the IAudioSpectrumObserver object. |
| int io.agora.mediaplayer.IMediaPlayer.unregisterMediaPlayerAudioSpectrumObserver | ( | IAudioSpectrumObserver | observer | ) |
Releases the audio frame spectrum observer.
| observer | The pointer to the IAudioSpectrumObserver object. |
| int io.agora.mediaplayer.IMediaPlayer.setAudioDualMonoMode | ( | int | mode | ) |
Sets the channel mode of the current audio file.
In a stereo music file, the left and right channels can store different audio data. According to your needs, you can set the channel mode to original mode, left channel mode, right channel mode, or mixed channel mode. For example, in the KTV scenario, the left channel of the music file stores the musical accompaniment, and the right channel stores the singing voice. If you only need to listen to the accompaniment, call this method to set the channel mode of the music file to left channel mode; if you need to listen to the accompaniment and the singing voice at the same time, call this method to set the channel mode to mixed channel mode.
open(String url, long startPos).| mode | The channel mode.
|
| int io.agora.mediaplayer.IMediaPlayer.registerVideoFrameObserver | ( | IMediaPlayerVideoFrameObserver | videoFrameObserver | ) |
Registers a video frame observer object.
You need to implement the IMediaPlayerVideoFrameObserver class in this method and register callbacks according to your scenarios. After you successfully register the video frame observer, the SDK triggers the registered callbacks each time a video frame is received.
| videoFrameObserver | The video observer, reporting the reception of each video frame. See IMediaPlayerVideoFrameObserver. |
| int io.agora.mediaplayer.IMediaPlayer.openWithAgoraCDNSrc | ( | String | src, |
| long | startPos | ||
| ) |
Open the Agora CDN media source.
| src | The src of the media file that you want to play. |
| startPos | The playback position (ms). |
| int io.agora.mediaplayer.IMediaPlayer.getAgoraCDNLineCount | ( | ) |
| int io.agora.mediaplayer.IMediaPlayer.switchAgoraCDNLineByIndex | ( | int | index | ) |
Switch Agora CDN lines.
| index | Specific CDN line index. |
| int io.agora.mediaplayer.IMediaPlayer.getCurrentAgoraCDNIndex | ( | ) |
| int io.agora.mediaplayer.IMediaPlayer.enableAutoSwitchAgoraCDN | ( | boolean | enable | ) |
Enable automatic CDN line switching.
| enable | Whether enable. |
| int io.agora.mediaplayer.IMediaPlayer.renewAgoraCDNSrcToken | ( | String | token, |
| long | ts | ||
| ) |
Update the CDN source token and timestamp.
| token | token. |
| ts | ts. |
| int io.agora.mediaplayer.IMediaPlayer.switchAgoraCDNSrc | ( | String | src, |
| boolean | syncPts | ||
| ) |
Switch the CDN source.
| src | Specific src. |
| syncPts | Live streaming must be set to false. |
| int io.agora.mediaplayer.IMediaPlayer.setSpatialAudioParams | ( | SpatialAudioParams | params | ) |
Enables or disables the spatial audio effect for the media player.
After successfully setting the spatial audio effect parameters of the media player, the SDK enables the spatial audio effect for the media player, and the local user can hear the media resources with a sense of space. If you need to disable the spatial audio effect for the media player, set the params parameter to null.
| params | The spatial audio effect parameters of the media player. See SpatialAudioParams. |
1.8.18