tencent cloud

Tencent Real-Time Communication

Release Notes and Announcements
Release Notes
Recent Product Announcement
TRTC Live (TUILiveKit) Product Launch Announcement
TRTC Conference Official Editions Launched
The commercial version of Conference is coming soon
Terms and Conditions Applicable to $9.9 Starter Package
Rules for the "First Subscription $100 Discount" Promotion
Announcement on the Start of Beta Testing for Multi-person Audio and Video Conference
TRTC Call Official Editions Launched
License Required for Video Playback in New Version of LiteAV SDK
TRTC to Offer Monthly Packages
Product Introduction
Overview
Concepts
Features
Strengths
Use Cases
Performance Statistics
Tencent RTC Quickplay: Experience Ultimate Real-Time Audio and Video Interaction!
Purchase Guide
Billing Overview
Free Minutes
Monthly subscription
Pay-as-you-go
TRTC Overdue and Suspension Policy
FAQs
Refund Instructions
User Tutorial
Free Demo
Call
Overview
Activate the Service
Run Demo
Integration
Offline Call Push
Conversational Chat
On-Cloud Recording
AI Noise Reduction
UI Customization
Calls integration to Chat
Additional Features
No UI Integration
Server APIs
Client APIs
Solution
ErrorCode
Release Notes
FAQs
Conference
Overview(TUIRoomKit)
Activate the Service (TUIRoomKit)
Run Demo(TUIRoomKit)
Integration(TUIRoomKit)
Screen Sharing (TUIRoomKit)
Schedule a meeting (TUIRoomKit)
In-meeting Call (TUIRoomKit)
UI Customization(TUIRoomKit)
Virtual Background (TUIRoomKit)
Conference Control (TUIRoomKit)
Cloud Recording (TUIRoomKit)
AI Noise Reduction (TUIRoomKit)
In-Conference Chat (TUIRoomKit)
Robot Streaming (TUIRoomKit)
Enhanced Features (TUIRoomKit)
Client APIs (TUIRoomKit)
Server APIs (TUIRoomKit)
FAQs (TUIRoomKit)
Error Code (TUIRoomKit)
SDK Update Log (TUIRoomKit)
Live
Billing of Video Live Component
Overview
Activating the Service (TUILiveKit)
Run Demo
No UI Integration
UI Customization
Live Broadcast Monitoring
Video Live Streaming
Voice Chat Room
Advanced Features
Client APIs
Server APIs
Error Codes
Release Notes
FAQs
RTC Engine
Activate Service
SDK Download
API Examples
Usage Guidelines
API Reference Manual
Advanced Features
AI Integration
Overview
Configure MCP Server
Install Skills
Integration Guide
FAQ
RTC RESTFUL API
History
Introduction
API Category
Room Management APIs
Stream mixing and relay APIs
On-cloud recording APIs
Data Monitoring APIs
Pull stream Relay Related interface
Web Record APIs
AI Service APIs
Cloud Slicing APIs
Cloud Moderation APIs
Making API Requests
Call Quality Monitoring APIs
Usage Statistics APIs
Data Types
Appendix
Error Codes
Console Guide
Application Management
Package Management
Usage Statistics
Monitoring Dashboard
Development Assistance
Solution
Real-Time Chorus
FAQs
Migration Guide
Billing
Features
UserSig
Firewall Restrictions
How to Downsize Installation Package
Android and iOS
Web
Flutter
Electron
TRTCCalling for Web
Audio and Video Quality
Others
Legacy Documentation
RTC RoomEngine SDK(Old)
Integrating TUIRoom (Web)
Integrating TUIRoom (Android)
Integrating TUIRoom (iOS)
Integrating TUIRoom (Flutter)
Integrating TUIRoom (Electron)
TUIRoom APIs
On-Cloud Recording and Playback (Old)
RTC Analytics Monthly Packages (Previous Version)
Protocols and Policies
Compliance
Security White Paper
Notes on Information Security
Service Level Agreement
Apple Privacy Policy: PrivacyInfo.xcprivacy
TRTC Policy
Privacy Policy
Data Processing And Security Agreement
Glossary

Background Music

PDF
Focus Mode
Font Size
Last updated: 2025-06-23 14:17:51
this document primarily introduces how to use RTC Room Engine SDK to implement relevant features of background music.

Prerequisites

Before using the background music settings-related features provided by RTC Room Engine SDK, you need to log in to the SDK first.

User Guide

Start/Stop Playing Background Music

iOS
Android
You can start or stop playing background music by calling startPlayMusic and stopPlayMusic two APIs.
When calling startPlayMusic to start playing background music, you need to input a parameter in types of TXAudioMusicParam to set playback control information. TXAudioMusicParam contains following information, which you can set separately:
Enumeration Types
Description
id
Field Meaning: Music ID.
Special Instructions: The SDK allows playback of multiple music streams. Therefore, IDs are required for tagging to control the start, stop, and volume of the music.
endTimeMS
Field Meaning: Music end playback time point, in milliseconds, with 0 indicating playback to the end of the file.
isShortFile
Field Meaning: Whether the playback is a short music file.
Recommended Value:
YES: Short music files that need to be repeated.
NO: Normal music file. Default value: NO.
loopCount
Field Meaning: Number of music loops.
Recommended Value: The value range is from 0 to any positive integer. The default value is 0. 0 means play the music once; 1 means play the music twice; and so on.
path
Field Meaning: Complete path or URL address of the sound effect file. Supported audio formats include MP3, AAC, M4A, WAV.
publish
Field Meaning: Whether to transmit music to remote end.
Recommended Value:
YES: The music can be played locally while the remote user can also hear it.
NO: The anchor can only hear the music locally, and the remote audience cannot hear it. Default value: NO.
startTimeMS
Field Meaning: Music start playback time point, in milliseconds.
You can start or stop playing background music by calling startPlayMusic and stopPlayMusic two APIs.
When calling startPlayMusic to start playing background music, you need to input a parameter in types of AudioMusicParam to set playback control information. AudioMusicParam contains following information, which you can set separately:
Enumeration Types
Description
id
Field Meaning: Music ID.
Special Instructions: The SDK allows playback of multiple music streams. Therefore, IDs are required for tagging to control the start, stop, and volume of the music.
endTimeMS
Field Meaning: Music end playback time point, in milliseconds, with 0 indicating playback to the end of the file.
isShortFile
Field Meaning: Whether the playback is a short music file.
Recommended Value:
YES: Short music files that need to be repeated.
NO: Normal music file. Default value: NO.
loopCount
Field Meaning: Number of music loops.
Recommended Value: The value range is from 0 to any positive integer. The default value is 0. 0 means play the music once; 1 means play the music twice; and so on.
path
Field Meaning: Complete path or URL address of the sound effect file. Supported audio formats include MP3, AAC, M4A, WAV.
publish
Field Meaning: Whether to transmit music to remote end.
Recommended Value:
YES: The music can be played locally while the remote user can also hear it.
NO: The anchor can only hear the music locally, and the remote audience cannot hear it. Default value: NO.
startTimeMS
Field Meaning: Music start playback time point, in milliseconds.
The following is a simple example of starting/stopping playing background music:
iOS
Android
import RTCRoomEngine
import TXLiteAVSDK_Professional

let audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager()

// Start background music playback.
let musicParam = TXAudioMusicParam()
musicParam.id = 0 // Replace with your own Music ID
musicParam.path = "path" // Replace with the full path or URL address of the music file
musicParam.publish = true // Transmit music to remote end
musicParam.loopCount = 0 // Replace with the number of times you need to loop playback
audioEffectManager.startPlayMusic(musicParam) { code in
if code == 0 {
// Playback started successfully
} else {
// Playback start 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.

TXAudioEffectManager audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager();

int id = 0; // Replace with your own Music ID
String path = "path"; // Replace with the full path or URL address of the music file.
// Start background music playback.
TXAudioEffectManager.AudioMusicParam musicParam = new TXAudioEffectManager.AudioMusicParam(id, path);
musicParam.publish = true; // Transmit music to remote end.
musicParam.loopCount = 0; // Replace with the number of times you need to loop playback.
audioEffectManager.startPlayMusic(musicParam);

// Stop background music playback.
audioEffectManager.stopPlayMusic(id); // Replace with the Music ID you need to stop.

Set Background Music Volume

You can set the background music volume by calling the setAllMusicVolume API and passing an Int value.
The passed-in Int value represents the volume, with a value range of 0 - 100. The following is an example of calling setAllMusicVolume to set the background music volume:
iOS
Android
import RTCRoomEngine
import TXLiteAVSDK_Professional

let audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager()

let volume = 60 // Replace with the volume you need to set
audioEffectManager.setAllMusicVolume(volume)
TXAudioEffectManager audioEffectManager = TUIRoomEngine.sharedInstance().getTRTCCloud().getAudioEffectManager();

int volume = 60; // Replace with the volume you need to set
audioEffectManager.setAllMusicVolume(volume);



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback