MusicStore provides a complete set of music playback management APIs, including starting/pausing/resuming/stopping playback and volume control. Through this class, BGM playback functionality can be implemented in live rooms.MusicStore instance, passing a valid live room ID.Property | Type | Description |
playURL | ValueListenable<String?> | Currently playing music URL. null means no music is playing. |
playStatus | Current playback status. | |
playProgress | ValueListenable<int> | Current playback progress (unit: milliseconds). |
totalDuration | ValueListenable<int> | Total duration of current music (unit: milliseconds). 0 means unknown. |
musicVolume | ValueListenable<int> | BGM volume, range 0 - 100, default 60. |
Function | Description |
Create music playback management instance. | |
Music playback event callbacks. | |
Music playback event callbacks. | |
Start playing music. | |
Pause playback. | |
Resume playback. | |
Stop playback. | |
Seek to specified position. | |
Set BGM volume. | |
Set pitch adjustment. |
Future<CompletionHandler> startPlay(AudioMusicParam param);
onPlayError for details.Parameter | Type | Description |
param |
void pausePlay();
void resumePlay();
void stopPlay();
void seek(int ms);
Parameter | Type | Description |
ms | Int | Target playback position in milliseconds. |
void setMusicVolume(int volume);
Parameter | Type | Description |
volume | Int | BGM volume, range 0 - 100. |
void setPitch(double pitch);
Parameter | Type | Description |
pitch | Double | Pitch adjustment value, range -12 ~ 12. Positive values raise the pitch, negative values lower it. |
Enum Value | Value | Description |
idle | 0 | Idle, not playing. |
playing | 1 | Playing. |
paused | 2 | Paused. |
loading | 3 | Loading (e.g. buffering network resource). |
Property | Type | Description |
playURL | ValueListenable<String?> | Currently playing music URL. null means no music is playing. |
playStatus | Current playback status. | |
playProgress | ValueListenable<int> | Current playback progress (unit: milliseconds). |
totalDuration | ValueListenable<int> | Total duration of current music (unit: milliseconds). 0 means unknown. |
musicVolume | ValueListenable<int> | BGM volume, range 0 - 100, default 60. |
Property | Type | Description |
id | int | Music ID. Since the SDK allows playing multiple tracks at the same time, this ID is
used to mark a track for start/stop/volume control, etc. When 0, an ID will be
generated internally based on path. |
path | String? | Full path or URL of the audio file. Supported formats: MP3, AAC, M4A, WAV. |
loopCount | int | Number of times to loop the track. 0 means play once without looping. |
void onPlayCompleted(String playURL) {}
Parameter | Type | Description |
playURL | String | The music URL that finished playing. |
void onPlayError(String playURL, int code) {}
Parameter | Type | Description |
playURL | String | The music URL that encountered error. |
code | Int | Error code, passed through from TRTC SDK. Common error codes are as follows: 0 (Success): Operation succeeded. -4001 (ERR_BGM_OPEN_FAILED): Failed to open file, invalid audio data or FFMPEG protocol not found. -4002 (ERR_BGM_DECODE_FAILED): Audio file decoding failed, file may be corrupted or encoding format unrecognized. -4003 (ERR_BGM_OVER_LIMIT): Number of preloaded music exceeded the limit. -4004 (ERR_BGM_INVALID_OPERATION): Invalid operation, e.g., calling preload during playback. -4005 (ERR_BGM_INVALID_PATH): Invalid path, please check if the file path points to a valid music file. -4006 (ERR_BGM_INVALID_URL): Invalid URL, please ensure the URL is accessible (iOS/Mac requires HTTPS). -4007 (ERR_BGM_NO_AUDIO_STREAM): No audio stream, please confirm the file is a valid audio file and not corrupted. -4008 (ERR_BGM_FORMAT_NOT_SUPPORTED): Format not supported. Mobile supports: mp3, aac, m4a, wav, ogg, mp4, mkv. Desktop supports: mp3, aac, m4a, wav, mp4, mkv. -4009 (ERR_CONCURRENT_BGM_OVER_LIMIT): Number of concurrent BGM playback exceeded the limit (max 10). |
フィードバック