IMediaPlayer

This class provides media player functions and supports multiple instances.

AdjustPlayoutVolume

Adjusts the local playback volume.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	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.

AdjustPublishSignalVolume

Adjusts the volume of the media file for publishing.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int AdjustPublishSignalVolume(int volume);

Details

After connected to the Agora server, you can call this method to adjust the volume of the media file heard by the remote user.

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.

GetDuration

Gets the duration of the media resource.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetDuration(int64& duration);

Parameters

duration
An output parameter. The total duration (ms) of the media file.

Returns

  • 0: Success.
  • < 0: Failure.

GetMediaPlayerId

Gets the ID of the media player.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetMediaPlayerId();

Returns

  • Success. The ID of the media player.
  • < 0: Failure.

GetMute

Reports whether the media resource is muted.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetMute(bool muted);

Parameters

mute
An output parameter. Whether the media file is muted:
  • true: The media file is muted.
  • false: The media file is unmuted.

Returns

  • 0: Success.
  • < 0: Failure.

GetPlayoutVolume

Gets the local playback volume.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetPlayoutVolume(int volume);

Parameters

volume
An output parameter. The local playback volume, which ranges from 0 to 100:
  • 0: Mute.
  • 100: (Default) The original volume.

Returns

  • 0: Success.
  • < 0: Failure.

GetPlayPosition

Gets current local playback progress.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetPlayPosition(int64& pos);

Parameters

pos
The playback position (ms) of the audio effect file.

Returns

GetPublishSignalVolume

Gets the volume of the media file for publishing.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetPublishSignalVolume(int volume);

Parameters

volume
An output parameter. The remote playback volume.

Returns

  • 0: Success.
  • < 0: Failure.

GetState

Gets current playback state.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	EMEDIA_PLAYER_STATE GetState();

Returns

The current playback state. See EMEDIA_PLAYER_STATE.

GetStreamCount

Gets the number of the media streams in the media resource.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetStreamCount(int64& count);

Details

Attention: Call this method after you call Open and receive the FOnPlayerSourceStateChanged callback reporting the state PLAYER_STATE_OPEN_COMPLETED.

Parameters

count
An output parameter. The number of the media streams in the media resource.

Returns

GetStreamInfo

Gets the detailed information of the media stream.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int GetStreamInfo(int64 index, FPlayerStreamInfo& info);

Details

Attention: Call this method after calling GetStreamCount.

Parameters

index
The index of the media stream.
This parameter needs to be less than the count parameter of GetStreamCount.
info
An output parameter. The detailed information of the media stream. See FPlayerStreamInfo.

Returns

  • 0: Success.
  • < 0: Failure.

Mute

Sets whether to mute the media file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Mute(bool 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.

Open

Opens the media resource.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Open(FString url, int64 startPos);

Details

Attention:

This method is called asynchronously.

If you need to play a media file, make sure you receive the FOnPlayerSourceStateChanged callback reporting PLAYER_STATE_OPEN_COMPLETED before calling the Play method to play the file.

Parameters

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.

Returns

  • 0: Success.
  • < 0: Failure.

OpenWithCustomSource

Opens the custom media resource file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int OpenWithCustomSource(int64 startPos, UIMediaPlayerCustomDataProvider* provider);

Details

Deprecated:
This method is deprecated, use OpenWithMediaSource instead.

This method allows you to open custom media resource files. For example, you can call this method to open encrypted media resources.

Parameters

startPos
The starting position (ms) for playback. Default value is 0.
provider
The callback for custom media resource files. See IMediaPlayerCustomDataProvider.

Returns

  • 0: Success.
  • < 0: Failure.

OpenWithMediaSource

Opens a media file and configures the playback scenarios.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int OpenWithMediaSource(const FAgoraMediaSource& source);

Details

This method supports opening media files of different sources, including a custom media source, and allows you to configure the playback scenarios.

Parameters

source
Media resources. See FAgoraMediaSource.

Returns

  • 0: Success.
  • < 0: Failure.

Pause

Pauses the playback.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Pause();

Returns

  • 0: Success.
  • < 0: Failure.

Play

Plays the media file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Play();

Details

After calling Open or Seek, you can call this method to play the media file.

Returns

  • 0: Success.
  • < 0: Failure.

PlayPreloadedSrc

Plays preloaded media resources.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int PlayPreloadedSrc(FString src);

Details

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 FOnPlayerSourceStateChanged 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.

Note:

If you call this method when playback is paused, this method does not take effect until playback is resumed.

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.

PreloadSrc

Preloads a media resource.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int PreloadSrc(FString src, int64 startPos);

Details

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 FOnPreloadEvent callback, the preload is successful; If you receive the PLAYER_PRELOAD_EVENT_ERROR event in the FOnPreloadEvent 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.

Note:

Agora does not support preloading duplicate media resources to the playlist. However, you can preload the media resources that are being played to the playlist again.

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.

registerAudioFrameObserver [1/2]

Registers a PCM audio frame observer object.

Details

You need to implement the IAudioPcmFrameSink 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.

Parameters

observer
The audio frame observer, reporting the reception of each audio frame. See IAudioPcmFrameSink.

Returns

  • 0: Success.
  • < 0: Failure.

RegisterAudioFrameObserver

Registers an audio frame observer object.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int RegisterAudioFrameObserver(UIAudioPcmFrameSink* observer, ERAW_AUDIO_FRAME_OP_MODE_TYPE mode = ERAW_AUDIO_FRAME_OP_MODE_TYPE::RAW_AUDIO_FRAME_OP_MODE_READ_ONLY);

Parameters

observer

The audio frame observer, reporting the reception of each audio frame. See IAudioPcmFrameSink.

mode

The use mode of the audio frame. See ERAW_AUDIO_FRAME_OP_MODE_TYPE.

Returns

  • 0: Success.
  • < 0: Failure.

RegisterPlayerSourceObserver

Registers a media player observer.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int RegisterPlayerSourceObserver(UIMediaPlayerSourceObserver* observer);

Parameters

observer
The player observer, listening for events during the playback. See IMediaPlayerSourceObserver.

Returns

  • 0: Success.
  • < 0: Failure.

RegisterVideoFrameObserver

Registers a video frame observer object.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int RegisterVideoFrameObserver(UIVideoFrameObserver* observer);

Details

You need to implement the IVideoFrameObserver 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.

Parameters

observer
The video observer, reporting the reception of each video frame. See IVideoFrameObserver.

Returns

  • 0: Success.
  • < 0: Failure.

Resume

Resumes playing the media file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Resume();

Returns

  • 0: Success.
  • < 0: Failure.

Seek

Seeks to a new playback position.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Seek(int64 newPos);

Details

After successfully calling this method, you will receive the FOnPlayerEvent callback, reporting the result of the seek operation to the new playback position.

To play the media file from a specific position, do the following:
  • Call this method to seek to the position you want to begin playback.
  • Call the Play method to play the media file.

Parameters

newPos
The new playback position (ms).

Returns

  • 0: Success.
  • < 0: Failure.

SelectAudioTrack

Selects the audio track used during playback.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SelectAudioTrack(int index);

Details

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.

Attention: You need to call this method after calling GetStreamInfo to get the audio stream index value.

Parameters

index
The index of the audio track.

Returns

  • 0: Success.
  • < 0: Failure.

SetAudioPitch

Sets the pitch of the current media resource.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetAudioPitch(int pitch);

Details

Note: Call this method after calling Open.

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.

SetAudioDualMonoMode

Sets the channel mode of the current audio file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetAudioDualMonoMode(EAUDIO_DUAL_MONO_MODE mode);

Details

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.

Attention:
  • Call this method after calling Open.
  • This method only applies to stereo audio files.

Parameters

mode
The channel mode. See EAUDIO_DUAL_MONO_MODE.

Returns

  • 0: Success.
  • < 0: Failure.

SetLoopCount

Sets the loop playback.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetLoopCount(int loopCount);

Details

If you want to loop, call this method and set the number of the loops.

When the loop finishes, the SDK triggers FOnPlayerSourceStateChanged and reports the playback state as PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED.

Parameters

loopCount
The number of times the audio effect loops:

Returns

  • 0: Success.
  • < 0: Failure.

SetPlaybackSpeed

Sets the channel mode of the current audio file.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetPlaybackSpeed(int speed);

Details

Call this method after calling Open.

Parameters

speed
The playback speed. Agora recommends that you limit this value to a range between 50 and 400, which is defined as follows:
  • 50: Half the original speed.
  • 100: The original speed.
  • 400: 4 times the original speed.

Returns

  • 0: Success.
  • < 0: Failure.

SetRenderMode

Sets the render mode of the media player.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetRenderMode(ERENDER_MODE_TYPE renderMode);

Parameters

renderMode

Sets the render mode of the view. See ERENDER_MODE_TYPE.

Returns

  • 0: Success.
  • < 0: Failure.

SetSpatialAudioParams

Enables or disables the spatial audio effect for the media player.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetSpatialAudioParams(const FSpatialAudioParams& params);

Details

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.

Parameters

params
The spatial audio effect parameters of the media player. See FSpatialAudioParams.

Returns

  • 0: Success.
  • < 0: Failure.

SetView

Sets the view.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetView(int64 view);

Parameters

view
The render view. On Windows, this parameter sets the window handle (HWND).

Returns

  • 0: Success.
  • < 0: Failure.

Stop

Stops playing the media track.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int Stop();

Returns

  • 0: Success.
  • < 0: Failure.

SwitchSrc

Switches the media resource being played.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SwitchSrc(FString src, bool syncPts);

Details

You can call this method to switch the media resource to be played according to the current network status. For example:
  • When the network is poor, the media resource to be played is switched to a media resource address with a lower bitrate.
  • When the network is good, the media resource to be played is switched to a media resource address with a higher bitrate.

After calling this method, if you receive the PLAYER_EVENT_SWITCH_COMPLETE event in the FOnPlayerEvent callback, the switch is successful; If you receive the PLAYER_EVENT_SWITCH_ERROR event in the FOnPlayerEvent callback, the switch fails.

Attention:
  • Ensure that you call this method after Open.
  • To ensure normal playback, pay attention to the following when calling this method:
    • Do not call this method when playback is paused.
    • Do not call the Seek method during switching.
    • Before switching the media resource, make sure that the playback position does not exceed the total duration of the media resource to be switched.

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.

Make sure to set this parameter as false if you need to play live streams, or the switch fails. If you need to play on-demand streams, you can set the value of this parameter according to your scenarios.

Returns

  • 0: Success.
  • < 0: Failure.

UnloadSrc

Unloads media resources that are preloaded.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int UnloadSrc(FString src);

Details

Attention:

This method cannot release the media resource being played.

Parameters

src
The URL of the media resource.

Returns

  • 0: Success.
  • < 0: Failure.

UnregisterAudioFrameObserver

Unregisters an audio frame observer.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int UnregisterAudioFrameObserver(UIAudioPcmFrameSink* observer);

Parameters

observer
The audio observer. See IAudioPcmFrameSink.

Returns

  • 0: Success.
  • < 0: Failure.

UnregisterPlayerSourceObserver

Releases a media player observer.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int UnregisterPlayerSourceObserver(UIMediaPlayerSourceObserver* observer);

Parameters

observer
The player observer, listening for events during the playback. See IMediaPlayerSourceObserver.

Returns

  • 0: Success.
  • < 0: Failure.

UnregisterVideoFrameObserver

Unregisters the video frame observer.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int UnregisterVideoFrameObserver(UIVideoFrameObserver* observer);

Parameters

observer
The video observer, reporting the reception of each video frame. See IVideoFrameObserver.

Returns

  • 0: Success.
  • < 0: Failure.