Class IMediaPlayerAbstract

This class provides media player functions and supports multiple instances.

Hierarchy

  • IMediaPlayer

Constructors

Methods

  • Adds one IMediaPlayerEvent listener. After calling this method, you can listen for the corresponding events in the IMediaPlayer object and obtain data through IMediaPlayerEvent. Depending on your project needs, you can add multiple listeners for the same event.

    Type Parameters

    Parameters

    • eventType: EventType

      The name of the target event to listen for. See IMediaPlayerEvent.

    • listener: IMediaPlayerEvent[EventType]

      The callback function for eventType. Take adding a listener for onPlayerSourceStateChanged as an example: // Create an onPlayerSourceStateChanged object const onPlayerSourceStateChanged = (connection: RtcConnection, elapsed: number) => {}; // Add one onPlayerSourceStateChanged listener engine.addListener('onPlayerSourceStateChanged', onPlayerSourceStateChanged);

    Returns void

  • Adjusts the local playback volume.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • volume: number

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

    Returns number

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

    Returns

    0: Success. < 0: Failure.

    Parameters

    • volume: number

      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 number

  • Gets the duration of the media resource.

    Returns

    The total duration (ms) of the media file.

    Returns number

  • Gets the ID of the media player.

    Returns

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

    Returns number

  • Reports whether the media resource is muted.

    Returns

    true : Reports whether the media resource is muted. false : Reports whether the media resource is muted.

    Returns boolean

  • Gets current local playback progress.

    Returns

    Returns the current playback progress (ms) if the call succeeds. < 0: Failure. See MediaPlayerReason.

    Returns number

  • Gets the path of the media resource being played.

    Returns

    The path of the media resource being played.

    Returns string

  • Gets the local playback volume.

    Returns

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

    Returns number

  • Gets the volume of the media file for publishing.

    Returns

    ≥ 0: The remote playback volume. < 0: Failure.

    Returns number

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

    Call this method after you call open and receive the onPlayerSourceStateChanged callback reporting the state PlayerStateOpenCompleted.

    Returns

    The number of the media streams in the media resource if the method call succeeds. < 0: Failure. See MediaPlayerReason.

    Returns number

  • Gets the detailed information of the media stream.

    Returns

    If the call succeeds, returns the detailed information of the media stream. See PlayerStreamInfo. null, if the method call fails.

    Parameters

    • index: number

      The index of the media stream. This parameter must be less than the return value of getStreamCount.

    Returns PlayerStreamInfo

  • Sets whether to mute the media file.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • muted: boolean

      Whether to mute the media file: true : Mute the media file. false : (Default) Unmute the media file.

    Returns number

  • Opens the media resource.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • url: string

      The path of the media file. Both local path and online path are supported.

    • startPos: number

      The starting position (ms) for playback. Default value is 0.

    Returns number

  • Opens a media file and configures the playback scenarios.

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

    Returns

    0: Success. < 0: Failure.

    Parameters

    • source: MediaSource

      Media resources. See MediaSource.

    Returns number

  • 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 onPlayerSourceStateChanged callback which reports the PlayerStatePlaying 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. If you call this method when playback is paused, this method does not take effect until playback is resumed.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • src: string

      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 number

  • 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 PlayerPreloadEventComplete event in the onPreloadEvent callback, the preload is successful; If you receive the PlayerPreloadEventError 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. Before calling this method, ensure that you have called open or openWithMediaSource to open the media resource successfully. 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.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • src: string

      The URL of the media resource.

    • startPos: number

      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 number

  • Registers an audio frame observer object.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • observer: IAudioPcmFrameSink

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

    • Optional mode: RawAudioFrameOpModeType

      The use mode of the audio frame. See RawAudioFrameOpModeType.

    Returns number

  • Registers a media player observer.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • observer: IMediaPlayerSourceObserver

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

    Returns number

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

    Returns

    0: Success. < 0: Failure.

    Parameters

    Returns number

  • Removes the specified IMediaPlayerEvent listener. For listened events, if you no longer need to receive the callback message, you can call this method to remove the corresponding listener.

    Type Parameters

    Parameters

    • eventType: EventType

      The name of the target event to listen for. See IMediaPlayerEvent.

    • Optional listener: IMediaPlayerEvent[EventType]

      The callback function for eventType. Must pass in the same function object in addListener . Take removing the listener for onPlayerSourceStateChanged as an example: // Create an onPlayerSourceStateChanged object const onPlayerSourceStateChanged = (state: MediaPlayerState, ec: MediaPlayerError) => {}; // Add one onPlayerSourceStateChanged listener engine.addListener('onPlayerSourceStateChanged', onPlayerSourceStateChanged); // Remove the onPlayerSourceStateChanged listener engine.removeListener('onPlayerSourceStateChanged', onPlayerSourceStateChanged);

    Returns void

  • Resumes playing the media file.

    Returns

    0: Success. < 0: Failure.

    Returns number

  • Seeks to a new playback position.

    If you call seek after the playback has completed (upon receiving callback onPlayerSourceStateChanged reporting playback status as PlayerStatePlaybackCompleted or PlayerStatePlaybackAllLoopsCompleted), the SDK will play the media file from the specified position. At this point, you will receive callback onPlayerSourceStateChanged reporting playback status as PlayerStatePlaying. 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 or play .

    Returns

    0: Success. < 0: Failure.

    Parameters

    • newPos: number

      The new playback position (ms).

    Returns number

  • 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. You need to call this method after calling getStreamInfo to get the audio stream index value.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • index: number

      The index of the audio track.

    Returns number

  • 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 MediaSource as true.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • playoutTrackIndex: number

      The index of audio tracks for local playback. You can obtain the index through getStreamInfo.

    • publishTrackIndex: number

      The index of audio tracks to be published in the channel. You can obtain the index through getStreamInfo.

    Returns number

  • 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. Call this method after calling open. This method only applies to stereo audio files.

    Returns

    0: Success. < 0: Failure.

    Parameters

    Returns number

  • Sets the pitch of the current media resource.

    Call this method after calling open.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • pitch: number

      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 number

  • 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 onPlayerSourceStateChanged and reports the playback state as PlayerStatePlaybackAllLoopsCompleted.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • loopCount: number

      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 number

  • Sets the channel mode of the current audio file.

    Call this method after calling open.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • speed: number

      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 number

  • Sets media player options.

    The media player supports setting options through key and value. The difference between this method and setPlayerOptionInString is that the value parameter of this method is of type Int, while the value of setPlayerOptionInString is of type String. These two methods cannot be used together.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • key: string

      The key of the option.

    • value: number

      The value of the key.

    Returns number

  • Sets media player options.

    The media player supports setting options through key and value. The difference between this method and setPlayerOptionInInt is that the value parameter of this method is of type String, while the value of setPlayerOptionInInt is of type String. These two methods cannot be used together.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • key: string

      The key of the option.

    • value: string

      The value of the key.

    Returns number

  • Sets the render mode of the media player.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • renderMode: RenderModeType

      Sets the render mode of the view. See RenderModeType.

    Returns number

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

    Returns

    0: Success. < 0: Failure.

    Parameters

    Returns number

  • Sets the view.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • view: any

      The render view.

    Returns number

  • Stops playing the media track.

    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.

    Returns

    0: Success. < 0: Failure.

    Returns number

  • 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: 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 onPlayerEvent callback report the PlayerEventSwitchComplete 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 PlayerEventSwitchError event indicating an error occurred during media resource switching. 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: string

      The URL of the media resource.

    • Optional syncPts: boolean

      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 number

  • Unloads media resources that are preloaded.

    This method cannot release the media resource being played.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • src: string

      The URL of the media resource.

    Returns number

  • Unregisters an audio frame observer.

    Returns

    0: Success. < 0: Failure.

    Parameters

    Returns number

  • Releases a media player observer.

    Returns

    0: Success. < 0: Failure.

    Parameters

    • observer: IMediaPlayerSourceObserver

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

    Returns number

  • Unregisters the video frame observer.

    Returns

    0: Success. < 0: Failure.

    Parameters

    Returns number

Generated using TypeDoc