IMediaPlayer class

Inheritance
  • Object
  • NativeClass
  • IMediaPlayer

Constructors

IMediaPlayer([NativeClassOptions? options])

Properties

$resource → NativeResource
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
ready Future<void>
Whether the instance is initialized
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

destroy() → void
inherited
getAudioTrackCount() FutureOr<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.
getPlaybackDuration() FutureOr<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.
getPosition() FutureOr<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.
getState() FutureOr<PlayerState>
@detail api @brief Get the state of the media player. @return The current state of the media player. See PlayerState{@link #PlayerState}. @note You can call this method after the creating a IMediaPlayer instance.
getTotalDuration() FutureOr<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.
getVolume(AudioMixingType type) FutureOr<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.
nativeCall<T>(String method, [List? args, NativeMethodMeta? meta]) Future<T>
Call instance method
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String filePath, MediaPlayerConfig config) FutureOr<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:
openWithCustomSource(MediaPlayerCustomSource source, MediaPlayerConfig config) FutureOr<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}.
pause() FutureOr<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.
pushExternalAudioFrame(AudioFrame audioFrame) FutureOr<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.
registerAudioFrameObserver(IMediaPlayerAudioFrameObserver observer) FutureOr<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.
resume() FutureOr<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.
selectAudioTrack(int index) FutureOr<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.
sendInstanceGet<T>(String property) Future<T>
Get instance property
inherited
sendInstancePropertiesGet(dynamic nativeClass) Future<Map<String, dynamic>>
Get instance properties
inherited
sendInstanceSet(String property, dynamic value) Future<void>
Set instance property
inherited
setAudioDualMonoMode(AudioMixingDualMonoMode mode) FutureOr<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.
setAudioPitch(int pitch) FutureOr<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.
setEventHandler(IMediaPlayerEventHandler handler) FutureOr<int>
@detail api @brief Set the event handler. @param handler See IMediaPlayerEventHandler{@link #IMediaPlayerEventHandler}. @return - 0: Success. - < 0: Failed.
setLoudness(float loudness) FutureOr<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.
setPlaybackSpeed(int speed) FutureOr<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.
setPosition(int position) FutureOr<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.
setProgressInterval(long interval) FutureOr<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.
setVolume(int volume, AudioMixingType type) FutureOr<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.
start() FutureOr<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
stop() FutureOr<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.
toString() String
A string representation of this object.
inherited
updateResource(NativeResource resource) → void
inherited

Operators

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

Static Properties

codegen_$namespace → dynamic
no setter