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);

Call timing

This method can be called either before or after joining the channel.

Restrictions

None.

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);

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.

Restrictions

None.

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 not muted.

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

GetPlaySrc

Gets the path of the media resource being played.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	FString GetPlaySrc();

Returns

The path of the media resource being played.

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 OnPlayerSourceStateChanged 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);

Call timing

Call this method after calling GetStreamCount.

Restrictions

None.

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);

Call timing

You can call this method either before or after joining a channel.

Restrictions

None.

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(const FString & url, int64 startPos);
Attention:

This method is called asynchronously.

Call timing

This method can be called either before or after joining the channel.

Restrictions

None.

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.

OpenWithMediaSource

Opens a media file and configures the playback scenarios.

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

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

Call timing

You can call this method either before or after joining a channel.

Restrictions

This method is called asynchronously. If you need to play a media file, make sure you receive the OnPlayerSourceStateChanged callback reporting PLAYER_STATE_OPEN_COMPLETED before calling the Play method to play the file.

Parameters

source
Media resources. See FAgoraMediaSource.

Returns

  • 0: Success.
  • < 0: Failure.

Pause

Pauses the playback.

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

Call timing

You can call this method either before or after joining a channel.

Restrictions

None.

Returns

  • 0: Success.
  • < 0: Failure.

Play

Plays the media file.

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

Call timing

Restrictions

None.

Returns

  • 0: Success.
  • < 0: Failure.

PlayPreloadedSrc

Plays preloaded media resources.

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

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.

GetMediaPlayerSourceObserver

Registers a media player observer.

UFUNCTION(BlueprintPure, Category = "Agora|IRtcEngine")
	UAgoraBPuIMediaPlayerSourceObserver* GetMediaPlayerSourceObserver();

Call timing

This method can be called either before or after joining the channel.

Restrictions

None.

Returns

Pointer to the IMediaPlayerSourceObserver object.

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);
  • If you call Seek after the playback has completed (upon receiving callback OnPlayerSourceStateChanged 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 OnPlayerSourceStateChanged reporting playback status as PLAYER_STATE_PLAYING.
  • If you call 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 orPlay .

Call timing

You can call this method either before or after joining a channel.

Restrictions

None.

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 OnPlayerSourceStateChanged and reports the playback state as PLAYER_STATE_PLAYBACK_ALL_LOOPS_COMPLETED.

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

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.

SetPlayerOptionWithInt

Sets media player options.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetPlayerOptionWithInt(const FString & key, int value);

The media player supports setting options through key and value.

The difference between this method and SetPlayerOptionWithString is that the value parameter of this method is of type Int, while the value of SetPlayerOptionWithString 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 or OpenWithMediaSource method.

Restrictions

None.

Parameters

key
The key of the option.
value
The value of the key.

Returns

  • 0: Success.
  • < 0: Failure.

SetPlayerOptionWithString

Sets media player options.

UFUNCTION(BlueprintCallable, Category = "Agora|IMediaPlayer")
	int SetPlayerOptionWithString(const FString & key, const FString & value);

The media player supports setting options through key and value.

The difference between this method and SetPlayerOptionWithInt is that the value parameter of this method is of type String, while the value of SetPlayerOptionWithInt 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 or OpenWithMediaSource method.

Restrictions

None.

Parameters

key
The key of the option.
value
The value of the key.

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.

SetView

Sets the view.

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

Call timing

You can call this method either before or after joining a channel.

Restrictions

None.

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();

After calling this method to stop playback, if you want to play again, you need to call Open or OpenWithMediaSource to open the media resource.

Call timing

Call this method after Play.

Restrictions

None.

Returns

  • 0: Success.
  • < 0: Failure.

SwitchSrc

Switches the media resource being played.

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

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 OnPlayerEvent callback, the switch is successful; If you receive the PLAYER_EVENT_SWITCH_ERROR event in the OnPlayerEvent 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(const 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.