Interface IMediaPlayer


public interface IMediaPlayer
  • Method Details

    • getMediaPlayerId

      int getMediaPlayerId()
      Returns:
      - Success. The ID of the media player. - < 0: Failure.
    • open

      int open(Uri uri, long startPos)
      Parameters:
      uri - The URI (Uniform Resource Identifier) of the media file.
      startPos - The starting position (ms) for playback. The default value is 0.
      Returns:
      - 0: Success. - < 0: Failure.
    • openWithMediaSource

      int openWithMediaSource(MediaPlayerSource source)
      Parameters:
      source - Media resources. See `MediaPlayerSource`.
      Returns:
      - 0: Success. - < 0: Failure.
    • play

      int play()
      Returns:
      - 0: Success. - < 0: Failure.
    • pause

      int pause()
      Returns:
      - 0: Success. - < 0: Failure.
    • stop

      int stop()
      Returns:
      - 0: Success. - < 0: Failure.
    • resume

      int resume()
      Returns:
      - 0: Success. - < 0: Failure.
    • seek

      int seek(long newPos)
      Parameters:
      newPos - The new playback position (ms).
      Returns:
      - 0: Success. - < 0: Failure.
    • setAudioPitch

      int setAudioPitch(int pitch)
      Parameters:
      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.
      Returns:
      - 0: Success. - < 0: Failure.
    • mute

      int mute(boolean muted)
      Parameters:
      muted - Whether to mute the media file: - `true`: Mute the media file. - `false`: (Default) Unmute the media file.
      Returns:
      - 0: Success. - < 0: Failure.
    • getMute

      boolean getMute()
      Returns:
      - `true`: Reports whether the media resource is muted. - `false`: Reports whether the media resource is muted.
    • adjustPlayoutVolume

      int adjustPlayoutVolume(int volume)
      Parameters:
      volume - The local playback volume, which ranges from 0 to 100: - 0: Mute. - 100: (Default) The original volume.
      Returns:
      - 0: Success. - < 0: Failure.
    • getPlayoutVolume

      int getPlayoutVolume()
      Returns:
      The local playback volume, which ranges from 0 to 100. - 0: Mute. - 100: (Default) The original volume.
    • getPlayPosition

      long getPlayPosition()
      Returns:
      - Returns the current playback progress (ms) if the call succeeds. - < 0: Failure. See `MediaPlayerReason`.
    • getDuration

      long getDuration()
      Returns:
      - If the method call succeeds, the SDK returns the total duration(ms) of the media file. - < 0: Failure.
    • getAudioBufferDelay

      int getAudioBufferDelay()
      Returns:
      The audio buffer delay (ms), if the method call succeeds. < 0: An error occurs. You can use MediaPlayerReason to check the reason.
    • getState

      Returns:
      The current playback state. See `MediaPlayerState`.
    • getStreamCount

      int getStreamCount()
      Returns:
      - The number of the media streams in the media resource if the method call succeeds. - < 0: Failure. See `MediaPlayerReason`.
    • setView

      int setView(View videoView)
      Parameters:
      videoView - The render view.
      Returns:
      - 0: Success. - < 0: Failure.
    • setRenderMode

      int setRenderMode(int mode)
      Parameters:
      mode - Sets the render mode of the view: - RENDER_MODE_HIDDEN (1): Hidden mode. Uniformly scale the video until it fills the visible boundaries (cropped). One dimension of the video may have clipped contents. - RENDER_MODE_FIT (2): Fit mode. Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit). Areas that are not filled due to the disparity in the aspect ratio are filled with black. - RENDER_MODE_ADAPTIVE (3): Adaptive mode. Deprecated: This enumerator is deprecated and not recommended for use.
      Returns:
      - 0: Success. - < 0: Failure.
    • getStreamInfo

      MediaStreamInfo getStreamInfo(int index)
      Parameters:
      index - The index of the media stream. This parameter must be less than the return value of `getStreamCount`.
      Returns:
      - If the call succeeds, returns the detailed information of the media stream. See `MediaStreamInfo`. - `NULL` is returned, if the method call fails.
    • setLoopCount

      int setLoopCount(int loopCount)
      Parameters:
      loopCount - The number of times the audio effect loops: - ≥ 0: Number of times for playing. For example, setting it to 0 means no loop playback, playing only once; setting it to 1 means loop playback once, playing a total of twice. - -1: Play the audio file in an infinite loop.
      Returns:
      - 0: Success. - < 0: Failure.
    • setPlaybackSpeed

      int setPlaybackSpeed(int speed)
      Parameters:
      speed - The playback speed. Agora recommends that you set this to a value between 30 and 400, defined as follows: - 30: 0.3 times the original speed. - 100: The original speed. - 400: 4 times the original speed.
      Returns:
      - 0: Success. - < 0: Failure.
    • selectAudioTrack

      int selectAudioTrack(int index)
      Parameters:
      index - The index of the audio track.
      Returns:
      - 0: Success. - < 0: Failure.
    • selectMultiAudioTrack

      int selectMultiAudioTrack(int playoutTrackIndex, int publishTrackIndex)
      Parameters:
      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`.
      Returns:
      - 0: Success. - < 0: Failure.
    • setPlayerOption

      int setPlayerOption(String key, int value)
      Parameters:
      key - The key of the option.
      value - The value of the key.
      Returns:
      - 0: Success. - < 0: Failure.
    • setPlayerOptionString

      int setPlayerOptionString(String key, String value)
      Parameters:
      key - The key of the option.
      value - The value of the key.
      Returns:
      - 0: Success. - < 0: Failure.
    • takeScreenshot

      int takeScreenshot(String filename)
      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

      int setExternalSubtitle(String url)
      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)
      Parameters:
      volume - The volume, which ranges from 0 to 400: - 0: Mute. - 100: (Default) The original volume. - 400: Four times the original volume (amplifying the audio signals by four times).
      Returns:
      - 0: Success. - < 0: Failure.
    • getPublishSignalVolume

      int getPublishSignalVolume()
      Returns:
      - ≥ 0: The remote playback volume. - < 0: Failure.
    • getPlaySrc

      String getPlaySrc()
      Returns:
      The path of the media resource being played.
    • switchSrc

      int switchSrc(String src, boolean syncPts)
      Parameters:
      src - The URL of the media resource.
      syncPts - Whether to synchronize the playback position (ms) before and after the switch: - `true`: Synchronize the playback position before and after the switch. - `false`: (Default) Do not synchronize the playback position before and after the switch.
      Returns:
      - 0: Success. - < 0: Failure.
    • preloadSrc

      int preloadSrc(String src, long startPos)
      Parameters:
      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.
      Returns:
      - 0: Success. - < 0: Failure.
    • playPreloadedSrc

      int playPreloadedSrc(String src)
      Parameters:
      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.
      Returns:
      - 0: Success. - < 0: Failure.
    • unloadSrc

      int unloadSrc(String src)
      Parameters:
      src - The URL of the media resource.
      Returns:
      - 0: Success. - < 0: Failure.
    • destroy

      int destroy()
      Returns:
      - ≥ 0: Success. Returns the ID of media player instance. - < 0: Failure.
    • registerPlayerObserver

      int registerPlayerObserver(IMediaPlayerObserver playerObserver)
      Parameters:
      playerObserver - The player observer, listening for events during the playback. See `IMediaPlayerObserver`.
      Returns:
      - 0: Success. - < 0: Failure.
    • unRegisterPlayerObserver

      int unRegisterPlayerObserver(IMediaPlayerObserver playerObserver)
      Parameters:
      playerObserver - The player observer, listening for events during the playback. See `IMediaPlayerObserver`.
      Returns:
      - 0: Success. - < 0: Failure.
    • registerAudioFrameObserver

      int registerAudioFrameObserver(IMediaPlayerAudioFrameObserver audioFrameObserver, int mode)
      Parameters:
      audioFrameObserver - The audio frame observer, reporting the reception of each audio frame. See `IMediaPlayerAudioFrameObserver`.
      mode - The use mode of the audio frame: - RAW_AUDIO_FRAME_OP_MODE_READ_ONLY (0): (Default) Read only mode. For example, when users acquire the data with the Agora SDK, then push the RTMP or RTMPS streams. - RAW_AUDIO_FRAME_OP_MODE_READ_WRITE (2): Read and write mode: Users read the data from AudioFrame, modify it, and then play it. For example, when users have their own audio-effect processing module and perform some voice pre-processing, such as a voice change.
      Returns:
      - 0: Success. - < 0: Failure.
    • registerMediaPlayerAudioSpectrumObserver

      int registerMediaPlayerAudioSpectrumObserver(IAudioSpectrumObserver observer, int intervalInMS)
      Registers the audio frame spectrum observer.
      Parameters:
      observer - The pointer to the {@link media::base::IAudioSpectrumObserver IAudioSpectrumObserver} object.
      Returns:
      - 0: Success. - < 0: Failure.
    • unregisterMediaPlayerAudioSpectrumObserver

      int unregisterMediaPlayerAudioSpectrumObserver(IAudioSpectrumObserver observer)
      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)
      Parameters:
      mode - The channel mode. - AUDIO_DUAL_MONO_STEREO (0): Original mode. - AUDIO_DUAL_MONO_L (1): Left channel mode. This mode replaces the audio of the right channel with the audio of the left channel, which means the user can only hear the audio of the left channel. - AUDIO_DUAL_MONO_R (2): Right channel mode. This mode replaces the audio of the left channel with the audio of the right channel, which means the user can only hear the audio of the right channel. - AUDIO_DUAL_MONO_MIX (3): Mixed channel mode. This mode mixes the audio of the left channel and the right channel, which means the user can hear the audio of the left channel and the right channel at the same time.
      Returns:
      - 0: Success. - < 0: Failure.
    • registerVideoFrameObserver

      int registerVideoFrameObserver(IMediaPlayerVideoFrameObserver videoFrameObserver)
      Parameters:
      videoFrameObserver - The video observer, reporting the reception of each video frame. See `IMediaPlayerVideoFrameObserver`.
      Returns:
      - 0: Success. - < 0: Failure.
    • openWithAgoraCDNSrc

      @Deprecated int openWithAgoraCDNSrc(String src, long startPos)
      Deprecated.
      4.6.0
      Open 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 int getAgoraCDNLineCount()
      Deprecated.
      4.6.0
      Gets the number of Agora CDN lines.
      Returns:
      - > 0: number of CDN. - <= 0: Failure.
    • switchAgoraCDNLineByIndex

      @Deprecated int switchAgoraCDNLineByIndex(int index)
      Deprecated.
      4.6.0
      Switch Agora CDN lines.
      Parameters:
      index - Specific CDN line index.
      Returns:
      - 0: Success. - < 0: Failure.
    • getCurrentAgoraCDNIndex

      @Deprecated int getCurrentAgoraCDNIndex()
      Deprecated.
      4.6.0
      Gets the line of the current CDN.
      Returns:
      - >= 0: Specific line. - < 0: Failure.
    • enableAutoSwitchAgoraCDN

      @Deprecated int enableAutoSwitchAgoraCDN(boolean enable)
      Deprecated.
      4.6.0
      Enable automatic CDN line switching.
      Parameters:
      enable - Whether enable.
      Returns:
      - 0: Success. - < 0: Failure.
    • renewAgoraCDNSrcToken

      @Deprecated int renewAgoraCDNSrcToken(String token, long ts)
      Deprecated.
      4.6.0
      Update the CDN source token and timestamp.
      Parameters:
      token - token.
      ts - ts.
      Returns:
      - 0: Success. - < 0: Failure.
    • switchAgoraCDNSrc

      @Deprecated int switchAgoraCDNSrc(String src, boolean syncPts)
      Deprecated.
      4.6.0
      Switch the CDN source.
      Parameters:
      src - Specific src.
      syncPts - Live streaming must be set to false.
      Returns:
      - 0: Success. - < 0: Failure.
    • setSpatialAudioParams

      int setSpatialAudioParams(SpatialAudioParams params)
      Parameters:
      params - The spatial audio effect parameters of the media player. See `SpatialAudioParams`.
      Returns:
      - 0: Success. - < 0: Failure.