MediaPlayer class

@brief Media player

Inheritance

Properties

$instance → dynamic
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

$createInstance(List args) → dynamic
Factory method for creating instances
override
$destroy() → void
inherited
$init(List args) → void
inherited
findOverrideIndices(List args, List<List<int>> indicesList) List<int>
查找重载参数下标列表 @desc android 构造函数存在重载 此方法通过实际传入参数与构造函数参数列表集合的比对,来获取当前实际的需要使用的参数列表
inherited
fn2AndroidClass(Function callback, dynamic nativeClass(), String methodName) → dynamic
与 ts runtime 中的 fn2AndroidClass 功能一致 将 Dart 函数转换为 Android 回调类实例供 Android 侧使用
inherited
getAudioTrackCount() Future<int?>
@detail api @brief Gets the track count of the current media file. @return + >= 0:Success. Return the track count of the current media file. - < 0:Failed. @note - Call this API only when audio is mixing. - This API is valid for audio file, not PCM data.
inherited
getPlaybackDuration() Future<int?>
@detail api @brief Gets the actual playback duration of the mixed media file, in milliseconds. @return - >0: Success, the actual playback time. - < 0: Failed. @note - 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 and the interval set by setProgressInterval{@link #IMediaPlayer#setProgressInterval} is above 0. - The API is valid for audio file, not PCM data.
inherited
getPosition() Future<int?>
@detail api @brief Gets the playback progress of the media file. @return - >0: Success, the playback progress of media file in ms. - < 0: Failed. @note - Call this API only when audio is mixing. - The API is valid for audio file, not PCM data.
inherited
getState() Future<PlayerState>
@brief Get media player state
override
getTotalDuration() Future<int?>
@detail api @brief Gets the duration of the media file. @return - >0: Success, the duration of the media file in milliseconds. - < 0: Failed. @note - Call this API only when audio is mixing. - The API is valid for audio file, not PCM data.
inherited
getVolume(AudioMixingType type) Future<int?>
@detail api @brief Gets the current volume. @param type See AudioMixingType{@link #AudioMixingType}. @return - >0: Success, the current volume. - < 0: Failed. @note Call this API only when audio is mixing, including media file mixing and PCM mixing.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(string filePath, MediaPlayerConfig config) Future<int?>
@detail api @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.
For audio file in PCM format, see openWithCustomSource{@link #IMediaPlayer#openWithCustomSource}. openWithCustomSource and this API are mutually exclusive. @param filePath Audio file paths.
URL of online file, URI of local file, full path to local file, or path to local file starting with /assets/ are supported. For URL of online file, only the https protocol is supported.
Recommended sample rate for audio effect files: 8KHz、16KHz、22.05KHz、44.1KHz、48KHz.
Local audio effect file formats supported by different platforms:
inherited
openWithCustomSource(MediaPlayerCustomSource source, MediaPlayerConfig config) Future<int?>
@detail api @brief Enable audio mixing with audio raw data.
To open the audio file, see open{@link #IMediaPlayer#open}. open and this API are mutually exclusive. @param source See MediaPlayerCustomSource{@link #MediaPlayerCustomSource}. @param config See MediaPlayerConfig{@link #MediaPlayerConfig}. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - After calling this API, you must call pushExternalAudioFrame{@link #IMediaPlayer#pushExternalAudioFrame} to push audio data and start the audio mixing. - To stop the raw data audio mixing, call stop{@link #IMediaPlayer#stop}.
inherited
pause() Future<int?>
@detail api @brief After calling open{@link #IMediaPlayer#open}, or start{@link #IMediaPlayer#start} to start audio mixing, call this API to pause audio mixing. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - After calling this API to pause audio mixing, call resume{@link #IMediaPlayer#resume} to resume audio mixing. - The API is valid for audio file, not PCM data.
inherited
pushExternalAudioFrame(AudioFrame audioFrame) Future<int?>
@detail api @brief Push PCM audio frame data for mixing. @param audioFrame See AudioFrame{@link #AudioFrame}.
- The audio sampling format must be S16. The data format within the audio buffer must be PCM, and its capacity size should be audioFrame.samples × audioFrame.channel × 2. - A specific sample rate and the number of channels must be specified. Setting them to automatic is not supported. @return - 0: Success. - < 0: Failed. @note - Before calling this method, the raw audio data mixing must be enabled through openWithCustomSource{@link #IMediaPlayer#openWithCustomSource}. - Suggestions: Before pushing data for the first time, please cache a certain amount of data (like 200 ms) on the application side, and then push it at once. Schedule subsequent push operation every 10 ms with audio data of 10 ms. - To pause the playback, just pause the push.
inherited
registerAudioFrameObserver(IMediaPlayerAudioFrameObserver observer) Future<int?>
@detail api @brief Register an observer to receive related callbacks when the local media file is mixing. @param observer See IMediaPlayerAudioFrameObserver{@link #IMediaPlayerAudioFrameObserver}. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note The API is valid for audio file, not PCM data.
inherited
resume() Future<int?>
@detail api @brief After calling pause{@link #IMediaPlayer#pause} to pause audio mixing, call this API to resume audio mixing. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note The API is valid for audio file, not PCM data.
inherited
selectAudioTrack(int index) Future<int?>
@detail api @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{@link #IMediaPlayer#getAudioTrackCount}. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - This API is valid for audio file, not PCM data. - After calling this API, you will receive onMediaPlayerEvent{@link #IMediaPlayerEventHandler#onMediaPlayerEvent} callback.
inherited
setAudioDualMonoMode(AudioMixingDualMonoMode mode) Future<int?>
@detail api @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. See AudioMixingDualMonoMode{@link #AudioMixingDualMonoMode}. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - Audio file is supported, but not PCM data.
inherited
setAudioPitch(int pitch) Future<int?>
@detail api @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. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - Support audio file only and not PCM data.
inherited
setEventHandler(IMediaPlayerEventHandler handler) Future<int?>
@detail api @brief Set the event handler. @param handler See IMediaPlayerEventHandler{@link #IMediaPlayerEventHandler}. @return - 0: Success. - < 0: Failed.
inherited
setLoudness(float loudness) Future<int?>
@detail api @brief To call enableVocalInstrumentBalance{@link #RTCEngine#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. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - The API is valid for audio file and PCM data.
inherited
setPlaybackSpeed(int speed) Future<int?>
@detail api @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. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - The API is valid for audio file and not PCM data.
inherited
setPosition(int position) Future<int?>
@detail api @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{@link #IMediaPlayer#getTotalDuration}. The value of position should be less than the total duration of the media file. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - The API is valid for audio file, not PCM data. - When playing online files, calling this API may cause playback delay. - After calling this API, you will receive onMediaPlayerEvent{@link #IMediaPlayerEventHandler#onMediaPlayerEvent} callback.
inherited
setProgressInterval(int interval) Future<int?>
@detail api @brief Set the interval of the periodic callback onMediaPlayerPlayingProgress{@link #IMediaPlayerEventHandler#onMediaPlayerPlayingProgress} during audio mixing. @param interval interval in ms.
- interval > 0: The callback is enabled. The actual interval is 10*(mod(10)+1). - interval <= 0: The callback is disabled. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note - Call this API only when audio is mixing. - This API is valid for audio file, not PCM data.
inherited
setVolume(int volume, AudioMixingType type) Future<int?>
@detail api @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 See AudioMixingType{@link #AudioMixingType}. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note Call this API only when audio is mixing.
inherited
start() Future<int?>
@detail api @brief Start playing the audio. Call this API when you call open{@link #IMediaPlayer#open} and set AutoPlay=False. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details. @note
inherited
stop() Future<int?>
@detail api @brief After calling open{@link #IMediaPlayer#open}, start{@link #IMediaPlayer#start}, or openWithCustomSource{@link #IMediaPlayer#openWithCustomSource} to start audio mixing, call this method to stop audio mixing. @return - 0: Success. - < 0 : Fail. See ReturnStatus{@link #ReturnStatus} for more details.
inherited
toString() String
A string representation of this object.
inherited
transformToPlatformConstructorArgs(List args, List<int> indices, Map<String, dynamic> typeMap, Map<String, dynamic> enumMap, Map<String, dynamic> classMap, String platformVar) List
实例化参数处理 将 pack 过后的 enum / class 转成 android / ios 平台侧的 enum / class
inherited
updateInstance(dynamic instance) → void
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited