RTC Room Engine
SDK to implement background music features.RTC Room Engine
SDK, you need to complete the SDK login.startPlayMusic
and stopPlayMusic
APIs respectively.startPlayMusic
to start background music playback, you need to pass a TXAudioMusicParam
parameter to set playback control information. TXAudioMusicParam
includes the following information, which you can set individually:Enumeration Types | Description |
id | Field Meaning: Music ID. Special Instructions: The SDK allows playing multiple music tracks simultaneously, so IDs are needed to control start, stop, volume, etc. |
endTimeMS | Field Meaning: Music play end time, in milliseconds. 0 means play until the end of the file. |
isShortFile | Field Meaning: Whether the played file is a short music file. Recommended Value: YES: short music file that needs to be played repeatedly; NO: normal music file. Default: NO. |
loopCount | Field Meaning: The number of times the music loops. Recommended Value: Value range is 0 to any positive integer. Default: 0. 0 means play the music once; 1 means play the music twice; and so on. |
path | Field Meaning: The full path or URL of the audio file. Supported audio formats include MP3, AAC, M4A, WAV. |
publish | Field Meaning: Whether to transmit the music to the remote end. Recommended Value: YES: The music is played locally and is also heard by remote users; NO: The host hears the music locally, but remote audience cannot. Default: NO. |
startTimeMS | Field Meaning: Music play start time, in milliseconds. |
startPlayMusic
and stopPlayMusic
APIs respectively.startPlayMusic
to start background music playback, you need to pass an AudioMusicParam
parameter to set playback control information. AudioMusicParam
includes the following information, which you can set individually:Enumeration Types | Description |
id | Field Meaning: Music ID. Special Instructions: The SDK allows playing multiple music tracks simultaneously, so IDs are needed to control start, stop, volume, etc. |
endTimeMS | Field Meaning: Music play end time, in milliseconds. 0 means play until the end of the file. |
isShortFile | Field Meaning: Whether the played file is a short music file. Recommended Value: YES: short music file that needs to be played repeatedly; NO: normal music file. Default: NO. |
loopCount | Field Meaning: The number of times the music loops. Recommended Value: Value range is 0 to any positive integer. Default: 0. 0 means play the music once; 1 means play the music twice; and so on. |
path | Field Meaning: The full path or URL of the audio file. Supported audio formats include MP3, AAC, M4A, WAV. |
publish | Field Meaning: Whether to transmit the music to the remote end. Recommended Value: YES: The music is played locally and is also heard by remote users; NO: The host hears the music locally, but remote audience cannot. Default: NO. |
startTimeMS | Field Meaning: Music play start time, in milliseconds. |
import RTCRoomEngineimport TXLiteAVSDK_Professionallet audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager()// Start background music playback.let musicParam = TXAudioMusicParam()musicParam.id = 0 // Replace with your own music IDmusicParam.path = "path" // Replace with the full path or URL of the music filemusicParam.publish = true // Publish the music to the remotemusicParam.loopCount = 0 // Replace with the number of times you need to loop playbackaudioEffectManager.startPlayMusic(musicParam) { code inif code == 0 {// Start playback successful} else {// Start playback failed}} onProgress: { progress, duration in// Playback progress callback.} onComplete: { _ in// Playback end callback.}// Stop background music playback.audioEffectManager.stopPlayMusic(musicId) // Replace with the music ID you need to stop playing
TXAudioEffectManager audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager();int id = 0; // Replace with your own music IDString path = "path"; // Replace with the full path or URL of the music file// Start background music playback.TXAudioEffectManager.AudioMusicParam musicParam = new TXAudioEffectManager.AudioMusicParam(id, path);musicParam.publish = true; // Publish the music to the remotemusicParam.loopCount = 0; // Replace with the number of times you need to loop playbackaudioEffectManager.startPlayMusic(musicParam);// Stop background music playback.audioEffectManager.stopPlayMusic(id); // Replace with the music ID you need to stop playing
setAllMusicVolume
API and passing an Int value.setAllMusicVolume
to set the background music volume:import RTCRoomEngineimport TXLiteAVSDK_Professionallet audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager()let volume = 60 // Replace with the volume level you need to setaudioEffectManager.setAllMusicVolume(volume)
TXAudioEffectManager audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager();int volume = 60; // Replace with the volume level you need to setaudioEffectManager.setAllMusicVolume(volume);
Was this page helpful?