Interface IMediaPlayer


public interface IMediaPlayer
  • 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

      int openWithMediaSource(MediaPlayerSource source)
      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

      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

      MediaStreamInfo getStreamInfo(int index)
    • 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

      int setPlayerOption(String key, int value)
      change player option before play a file
      Parameters:
      key - the key of the option param
      value - the value of option param
      Returns:
      - 0: Success. - < 0: Failure.
    • setPlayerOptionString

      int setPlayerOptionString(String key, String value)
      change player option before play a file
      Parameters:
      key - the key of the option param
      value - the value of option param
      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)
      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

      int switchSrc(String src, boolean syncPts)
      Parameters:
      src - The URL of the source
      syncPts - 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

      int preloadSrc(String src, long startPos)
      Parameters:
      src - The URL of the source
      startPos - play pos of the preload source
      Returns:
      int < 0 on behalf of an error, the value corresponds to one of MEDIA_PLAYER_REASON
    • playPreloadedSrc

      int playPreloadedSrc(String src)
      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

      int unloadSrc(String src)
      Unload a preloaded media source
      Parameters:
      src - Specific src.
      Returns:
      - 0: Success. - < 0: Failure.
    • destroy

      int destroy()
      Returns:
      - 0: Success. - < 0: Failure.
    • registerPlayerObserver

      int 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:
      playerObserver - The pointer to the IMediaPlayerObserver object.
      Returns:
      - 0: Success. - < 0: Failure.
    • unRegisterPlayerObserver

      int unRegisterPlayerObserver(IMediaPlayerObserver playerObserver)
      Releases the media player observer.
      Parameters:
      playerObserver - The pointer to the IMediaPlayerObserver object.
      Returns:
      - 0: Success. - < 0: Failure.
    • registerAudioFrameObserver

      int registerAudioFrameObserver(IMediaPlayerAudioFrameObserver audioFrameObserver, int mode)
    • 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)
      Set dual-mono output mode of the music file.
      Parameters:
      mode - See AudioDualMonoMode. Default in AUDIO_DUAL_MONO_STEREO
      Returns:
      - 0: Success. - < 0: Failure.
    • registerVideoFrameObserver

      int registerVideoFrameObserver(IMediaPlayerVideoFrameObserver videoFrameObserver)
    • 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)
      Set spatial audio params for the music file. It can be called after the media player was created.
      Parameters:
      params - See SpatialAudioParams. If it's not set, then the spatial audio will be disabled; or it will be enabled.
      Returns:
      - 0: Success. - < 0: Failure.