///
import { EventEmitter } from "events";
import { EventType, RTCMediaPlayerCALLBACK } from "../types/common";
import { AudioMixingDualMonoMode, AudioMixingType, MediaPlayerConfig, MediaPlayerCustomSource, ExternalAudioFrame } from "../types";
/** {en}
* @list overview
* @detail api
*/
/** {zh}
* @list overview
* @detail api
*/
declare class RTCMediaPlayer extends EventEmitter {
private instance;
constructor(player_id: number);
/** {en}
* @brief Open the audio file.
* You can only open one audio file with one player instance at the same time. For multiple audio files at the same time, create multiple player instances.
* @param file_path Audio file paths.
* URL of online file, URI of local file, or full path to local file. For URL of online file, only the https protocol is supported.
* Recommended sample rate for audio eccect files: 8KHz、16KHz、22.05KHz、44.1KHz、48KHz.
* Local audio effect file formats supported by different platforms:
*
* | mp3 | mp4 | aac | m4a | 3gp | wav | ogg | ts | wma |
* | Android | Y | Y | Y | Y | Y | Y | Y | | |
* | iOS/macOS | Y | Y | Y | Y | Y | Y | | | |
* | Windows | Y | Y | Y | Y | Y | Y | | Y | Y |
*
* Online audio effect file formats supported by different platforms.
*
* | mp3 | mp4 | aac | m4a | 3gp | wav | ogg | ts | wma |
* | Android | Y | | Y | Y | Y | Y | | | |
* | iOS/macOS | Y | | Y | Y | | Y | | | |
* | Windows | Y | | Y | Y | Y | Y | | Y | Y |
*
* @param config
* @returns + 0: Success
* + < 0: Failure.
* @group Media Player
* @order 1
*/
/** {zh}
* @brief 打开音乐文件。
* 一个播放器实例仅能够同时打开一个音乐文件。如果需要同时打开多个音乐文件,请创建多个音乐播放器实例。
* @param file_path 音乐文件路径。
* 支持在线文件的 URL、本地文件的 URI、或本地文件的绝对路径。对于在线文件的 URL,仅支持 https 协议。
* 推荐的采样率:8KHz、16KHz、22.05KHz、44.1KHz、48KHz。
* 不同平台支持的本地文件格式:
*
* | mp3 | mp4 | aac | m4a | 3gp | wav | ogg | ts | wma |
* | Android | Y | Y | Y | Y | Y | Y | Y | | |
* | iOS/macOS | Y | Y | Y | Y | Y | Y | | | |
* | Windows | Y | Y | Y | Y | Y | Y | | Y | Y |
*
* 不同平台支持的在线文件格式:
*
* | mp3 | mp4 | aac | m4a | 3gp | wav | ogg | ts | wma |
* | Android | Y | | Y | Y | Y | Y | | | |
* | iOS/macOS | Y | | Y | Y | | Y | | | |
* | Windows | Y | | Y | Y | Y | Y | | Y | Y |
*
* @param config
* @returns + `0`: 成功
* + `-1`: 失败
* @group Media Player
* @order 1
*/
open(file_path: string, config: MediaPlayerConfig): number;
/** {en}
* @brief Start playing the audio. Call this API when you call [open](85532#rtcmediaplayer-open) and set `AutoPlay=false`.
* @returns + 0: Success
* + < 0: Failure.
* @notes After calling this API, call [stop](85532#rtcmediaplayer-stop) to stop playing the audio file.
* @group Media Player
* @order 2
*/
/** {zh}
* @brief 播放音乐。你仅需要在调用 [open](85532#rtcmediaplayer-open),且未开启自动播放时,调用此方法。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes 调用本方法播放音频文件后,可调用 [`pause`](85532#rtcmediaplayer-pause) 方法暂停播放,或调用 [`stop`](85532#rtcmediaplayer-stop) 方法停止播放。
* @group Media Player
* @order 2
*/
start(): number;
/** {en}
* @brief After calling [open](85532#rtcmediaplayer-open) or [start](85532#rtcmediaplayer-start) to start audio mixing, call this method to stop audio mixing.
* @returns + 0: Success
* + < 0: Failure.
* @group Media Player
* @order 3
*/
/** {zh}
* @brief 调用 [open](85532#rtcmediaplayer-open) 或 [start](85532#rtcmediaplayer-start) 开始播放后,可以调用本方法停止。
* @returns + `0`: 成功
* + `-1`: 失败
* @group Media Player
* @order 3
*/
stop(): number;
/** {en}
* @brief After calling [open](85532#rtcmediaplayer-open), or [start](85532#rtcmediaplayer-start) to start audio mixing, call this API to pause audio mixing.
* @returns + 0: Success
* + < 0: Failure.
* @notes After calling this API to pause audio mixing, call [resume](85532#rtcmediaplayer-resume) to resume audio mixing.
* @group Media Player
* @order 4
*/
/** {zh}
* @brief 调用 [open](85532#rtcmediaplayer-open),或 [start](85532#rtcmediaplayer-start) 开始播放音频文件后,调用本方法暂停播放。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes 调用本方法暂停播放后,可调用 [resume](85532#rtcmediaplayer-resume) 恢复播放。
* @group Media Player
* @order 4
*/
pause(): number;
/** {en}
* @brief After calling [pause](85532#rtcmediaplayer-pause) to pause audio mixing, call this API to resume audio mixing.
* @returns + 0: Success
* + < 0: Failure.
* @group Media Player
* @order 5
*/
/** {zh}
* @brief 调用 [pause](85532#rtcmediaplayer-pause) 暂停音频播放后,调用本方法恢复播放。
* @returns + `0`: 成功
* + `-1`: 失败
* @group Media Player
* @order 5
*/
resume(): number;
/** {en}
* @brief Adjusts the volume of the specified audio mixing, including media file mixing and PCM mixing.
* @param volume The ratio of the volume to the original volume in % with overflow protection. The range is `[0, 400]` and the recommended range is `[0, 100]`.
* @param type
* @returns + 0: Success
* + < 0: Failure.
* @notes Call this API only when audio is mixing.
* @group Media Player
* @order 6
*/
/** {zh}
* @brief 调节指定混音的音量大小,包括音乐文件混音和 PCM 混音。
* @param volume 播放音量相对原音量的比值。单位为 %。范围为 `[0, 400]`,建议范围是 `[0, 100]`。带溢出保护。
* @param type
* @returns + `0`: 成功
* + `-1`: 失败
* @notes 仅在音频播放进行状态时,调用此方法。
* @group Media Player
* @order 6
*/
setVolume(volume: number, type: AudioMixingType): number;
/** {en}
* @brief Gets the current volume.
* @param type
* @returns + >0: Success, the current volume.
* + < 0: Failed.
* @notes Call this API only when audio is mixing, including media file mixing and PCM mixing.
* @group Media Player
* @order 7
*/
/** {zh}
* @brief 获取当前音量
* @param type
* @returns + >0: 成功, 当前音量值。
* + < 0: 失败
* @notes 仅在音频播放进行状态时,调用此方法。包括音乐文件混音和 PCM 混音。
* @group Media Player
* @order 7
*/
getVolume(type: AudioMixingType): number;
/** {en}
* @brief Gets the duration of the media file.
* @returns + >0: Success, the duration of the media file in milliseconds.
* + < 0: Failed.
* @notes + Call this API only when audio is mixing.
* + The API is valid for audio file, not PCM data.
* @group Media Player
* @order 8
*/
/** {zh}
* @brief 获取音乐文件时长。
* @returns + >0: 成功, 音乐文件时长,单位为毫秒。
* + < 0: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此接口仅支持音频文件,不支持 PCM 数据。
* @group Media Player
* @order 8
*/
getTotalDuration(): number;
/** {en}
* @brief Gets the actual playback duration of the mixed media file, in milliseconds.
* @returns + >0: Success, the actual playback time.
* + < 0: Failed.
* @notes
* + The actual playback time refers to the playback time of the song without being affected by stop, jump, double speed, and freeze. For example, if the song stops playing for 30 seconds at 1:30 or skips to 2:00, and then continues to play normally for 2 minutes, the actual playing time is 3 minutes and 30 seconds.
* + Call this API only when audio is mixing.
* + The API is valid for audio file, not PCM data.
* @group Media Player
* @order 9
*/
/** {zh}
* @brief 获取混音音乐文件的实际播放时长,单位为毫秒。
* @returns + >0: 实际播放时长。
* + < 0: 失败。
* @notes
* + 实际播放时长指的是歌曲不受停止、跳转、倍速、卡顿影响的播放时长。例如,若歌曲正常播放到 1:30 时停止播放 30s 或跳转进度到 2:00, 随后继续正常播放 2分钟,则实际播放时长为 3分30秒。
* + 仅在音频播放进行状态时,调用此方法。
* + 此接口仅支持音频文件,不支持 PCM 数据。
* @group Media Player
* @order 9
*/
getPlaybackDuration(): number;
/** {en}
* @brief Gets the playback progress of the media file.
* @returns + >0: Success, the playback progress of media file in ms.
* + < 0: Failed.
* @notes + Call this API only when audio is mixing.
* + The API is valid for audio file, not PCM data.
* @group Media Player
* @order 10
*/
/** {zh}
* @brief 获取音乐文件播放进度。
* @returns + >0: 成功, 音乐文件播放进度,单位为毫秒。
* + < 0: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此接口仅支持音频文件,不支持 PCM 数据。
* @group Media Player
* @order 10
*/
getPosition(): number;
/** {en}
* @brief Sets the starting playback position of the media file.
* @param position The starting position of the media file in milliseconds.
* You can get the total duration of the media file through [getTotalDuration](85532#rtcmediaplayer-gettotalduration). The value of position should be less than the total duration of the media file.
* @returns + 0: Success
* + < 0: Failure.
* @notes When playing online files, calling this API may cause playback delay.
* @group Media Player
* @order 11
*/
/** {zh}
* @brief 设置音乐文件的起始播放位置。
* @param position 音乐文件起始播放位置,单位为毫秒。
* 你可以通过 [getTotalDuration](85532#rtcmediaplayer-gettotalduration) 获取音乐文件总时长,position 的值应小于音乐文件总时长。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes 在播放在线文件时,调用此接口可能造成播放延迟的现象。
* @group Media Player
* @order 11
*/
setPosition(position: number): number;
/** {en}
* @brief Set the pitch of the local audio file mixing. Usually used in karaoke scenes.
* @param pitch The increase or decrease value compared with the original pitch of the music file. The range is `[-12, 12]`. The default value is 0. The pitch distance between two adjacent values is half a step. A positive value indicates a rising pitch, and a negative value indicates a falling pitch.
* @returns + 0: Success
* + < 0: Failure.
* @notes + Call this API only when audio is mixing.
* + Support audio file and not PCM data.
* @group Media Player
* @order 12
*/
/** {zh}
* @brief 开启变调功能,多用于 K 歌场景。
* @param pitch 与音乐文件原始音调相比的升高/降低值,取值范围为 `[-12,12]`,默认值为 0。每相邻两个值的音高距离相差半音,正值表示升调,负值表示降调。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 仅支持音乐文件混音,不支持 PCM 数据。
* @group Media Player
* @order 12
*/
setAudioPitch(pitch: number): number;
/** {en}
* @brief Sets the channel mode of the mixing of the media file.
* @param mode The mode of channel. The default channel mode is the same as the source file.
* @returns + 0: Success
* + < 0: Failure.
* @notes
* + Call this API only when audio is mixing.
* + Audio file is supported, but not PCM data.
* @group Media Player
* @order 13
*/
/** {zh}
* @brief 设置当前音乐文件的声道模式
* @param mode 声道模式。默认的声道模式和源文件一致
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 仅支持音频文件,不支持 PCM 数据。
* @group Media Player
* @order 13
*/
setAudioDualMonoMode(mode: AudioMixingDualMonoMode): number;
/** {en}
* @brief Gets the track count of the current media file.
* @returns + >= 0:Success. Return the track count of the current media file.
* + < 0:Failed.
* @notes
* + Call this API only when audio is mixing.
* + This API is valid for audio file, not PCM data.
* @group Media Player
* @order 14
*/
/** {zh}
* @brief 获取当前音乐文件的音轨数
* @returns + >= 0:成功,返回当前音乐文件的音轨数
* + < 0:方法调用失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此方法仅支持音乐文件,不支持 PCM 数据。
* @group Media Player
* @order 14
*/
getAudioTrackCount(): number;
/** {en}
* @brief Specifies the playback track of the current media file.
* @param index The specified playback audio track, starting from 0, and the range is `[0, getAudioTrackCount()-1]`. The value must be less than the return value of [getAudioTrackCount](85532#rtcmediaplayer-getaudiotrackcount).
* @returns + 0: Success
* + < 0: Failure.
* @notes
* + Call this API only when audio is mixing.
* + This API is valid for audio file, not PCM data.
* @group Media Player
* @order 15
*/
/** {zh}
* @brief 指定当前音乐文件的播放音轨
* @param index 指定的播放音轨,从 0 开始,取值范围为 `[0, getAudioTrackCount()-1]`。
* 设置的参数值需要小于 [getAudioTrackCount](85532#rtcmediaplayer-getaudiotrackcount) 的返回值
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此方法仅支持音乐文件,不支持 PCM 数据。
* @group Media Player
* @order 15
*/
selectAudioTrack(index: number): number;
/** {en}
* @brief Set the playback speed of the audio file.
* @param speed The ratio of the actual playback speed than that of the original speed of the audio file in %. The range is `[50,200]`. The default value is 100.
* @returns + 0: Success
* + < 0: Failure.
* @notes
* + Call this API only when audio is mixing.
* + The API is valid for audio file and not for PCM data.
* @group Media Player
* @order 16
*/
/** {zh}
* @brief 设置播放速度
* @param speed 播放速度与原始文件速度的比例,单位:%,取值范围为 `[50,200]`,默认值为 100。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此方法对音频文件可用,不支持 PCM 数据。
* @group Media Player
* @order 16
*/
setPlaybackSpeed(speed: number): number;
/** {en}
* @brief Set the interval of the periodic callback [onMediaPlayerPlayingProgress](85533#rtcmediaplayercallback-onmediaplayerplayingprogress) during audio mixing.
* @param interval interval in ms.
* + interval > 0: The callback is enabled. The actual interval is always a multiple of 10. If the provided value is not divisible by 10, it will automatically be rounded up using a ceiling function. For example, if 52 is provided, the actual interval will be 60ms.
* + interval <= 0: The callback is disabled.
* @returns + 0: Success
* + < 0: Failure.
* @notes
* + Call this API only when audio is mixing.
* + This API is valid for audio file, not PCM data.
* @group Media Player
* @order 17
*/
/** {zh}
* @brief 设置音频文件混音时,收到 [onMediaPlayerPlayingProgress](85533#rtcmediaplayercallback-onmediaplayerplayingprogress) 的间隔。
* @param interval 时间间隔,单位毫秒。
* + interval > 0 时,触发回调。实际间隔为 10 的倍数。如果输入数值不能被 10 整除,将自动向上取整。例如传入 `52`,实际间隔为 60 ms。
* + interval <= 0 时,不会触发回调。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此方法仅支持音频文件,不支持 PCM 数据。
* @group Media Player
* @order 17
*/
setProgressInterval(interval: string): number;
/** {en}
* @brief To call [enableVocalInstrumentBalance](85532#rtcvideo-enablevocalinstrumentbalance) to adjust the volume of the mixed media file or the PCM audio data, you must pass in its original loudness through this API.
* @param loudness Original loudness in lufs. The range is `[-70.0, 0.0]`.
* When the value is less than -70.0lufs, it will be adjusted to -70.0lufs by default, and if it is more than 0.0lufs, the loudness will not be equalized. The default value is 1.0lufs, which means no processing.
* @returns + 0: Success
* + < 0: Failure.
* @notes + Call this API only when audio is mixing.
* + The API is valid for audio file and PCM data.
* @group Media Player
* @order 18
*/
/** {zh}
* @brief 如果你需要使用 [`enableVocalInstrumentBalance`](85532#rtcvideo-enablevocalinstrumentbalance) 对音频文件/PCM 音频数据设置音量均衡,你必须通过此接口传入其原始响度。
* @param loudness 原始响度,单位:lufs,取值范围为 `[-70.0, 0.0]`。
* 当设置的值小于 -70.0lufs 时,则默认调整为 -70.0lufs,大于 0.0lufs 时,则不对该响度做音量均衡处理。默认值为 1.0lufs,即不做处理。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes + 仅在音频播放进行状态时,调用此方法。
* + 此方法对音频文件和音频裸数据播放都可用。
* @group Media Player
* @order 18
*/
setLoudness(loudness: number): number;
/** {en}
* @brief Register an observer to receive related callbacks when the local media file is mixing.
* @returns + 0: Success
* + < 0: Failure.
* @notes
* @group Media Player
* @order 19
*/
/** {zh}
* @brief 注册回调句柄以在本地音乐文件混音时,收到相关回调。
* @returns + `0`: 成功
* + `-1`: 失败
* @notes 触发回调 [onMediaPlayerStateChanged](85533#rtcmediaplayercallback-onmediaplayerstatechanged) 和 [onMediaPlayerPlayingProgress](85533#rtcmediaplayercallback-onmediaplayerplayingprogress)。
* @group Media Player
* @order 19
*/
setEventHandler(): number;
/** {zh}
* @brief 启动音频裸数据混音。
* @param source 数据源
* @param config 配置
* @return + 0: 调用成功。
* + < 0 : 调用失败。
* @notes + 要播放音乐文件,参看 [`open`](85532#rtcmediaplayer-open)。`open` 与此 API 互斥。
* + 调用本方法启动后,再调用 [`pushExternalAudioFrame`](85532#rtcvideo-pushexternalaudioframe) 推送音频数据,才会开始混音。
* + 如要结束 PCM 音频数据混音,调用 [`stop`](85532#rtcmediaplayer-stop)。
* @group Media Player
* @order 22
*/
openWithCustomSource(source: MediaPlayerCustomSource, config: MediaPlayerConfig): number;
/** {zh}
* @brief 推送用于混音的 PCM 音频帧数据
* @param audio_frame 音频帧
* @return + 0: 成功
* + < 0: 失败
* @notes + 调用该方法前,须通过 [`openWithCustomSource`](85532#rtcmediaplayer-openwithcustomsource) 启动外部音频流混音。
* + 使用参考建议:首次推送数据,请在应用侧先缓存一定数据(如 200 毫秒),然后一次性推送过去;此后的推送操作定时 10 毫秒一次,并且每次的音频数据量为 10 毫秒数据量。
* + 如果要暂停播放,暂停推送即可。
* @group Media Player
* @order 23
*/
pushExternalAudioFrame(frame: ExternalAudioFrame): any;
/**
* @private
*/
fire(event: string, ...args: any[]): void;
/**
* @hidden
*/
private callback;
/**
* @hidden
*/
processCallback(event: EventType): void;
}
declare interface RTCMediaPlayer {
on(evt: "onMediaPlayerStateChanged", cb: RTCMediaPlayerCALLBACK["onMediaPlayerStateChanged"]): this;
on(evt: "onMediaPlayerPlayingProgress", cb: RTCMediaPlayerCALLBACK["onMediaPlayerPlayingProgress"]): this;
}
export default RTCMediaPlayer;