Guide · Developer
How to Play Music in a Voice Chat Room
Play music in a voice chat room with VoltKit RTC: switch the music add-on on, publish a song from the browser or a phone, and see who pays while it plays.
- Author
- VoltKit
- Published
- Reading time
- 6 min read
A voice chat room with music needs two things a microphone cannot give it: the song has to reach the room clean, and it has to stay apart from the host's voice. A host who plays a song through their speakers and lets the microphone pick it up sends the room a thin, late copy, chewed up by echo cancellation, whose whole job is to remove that sound. This guide plays the song from inside the app instead, with VoltKit RTC's publishMusic, and covers the project switch, the code for hosts and listeners on each platform, and who pays while it plays. The code comes from the Music docs.
What you get
- From a browser host, the room hears the music clean, as audio in its own right, encoded for music: 128 kbps stereo, with silence suppression off so quiet passages are not chopped. An Android host mixes it into its microphone's track, at the microphone's quality.
- Music and microphone have separate switches: the host can mute themselves and let the song play, or stop the music and keep talking.
- In the browser the music is its own track, so each listener can turn it down without losing the host.
Step 1: switch the music add-on on
Music in a voice room is the music add-on. Open the project in the VoltKit console, go to Settings → Media and quality, and turn on Music add-on; it sits under audio. New projects start with it off. A project with video on may always publish music.
While the add-on is off in a voice project, publishMusic is refused with the code media-disabled and this message, and the microphone is untouched:
Music is not enabled for this project. Enable the Music add-on in the VoltKit console: project → Settings → Media and quality.
Turning the switch on needs no rejoin: the host's next publishMusic goes through. Only roles that may publish (host, cohost) can play music; anyone else gets forbidden.
Step 2: play a song from the browser
In the browser SDK, publishMusic takes an <audio> or <video> element, a MediaStream or a MediaStreamTrack. Call it from a click, so the browser lets the page play sound:
const song = document.querySelector("audio") as HTMLAudioElement; // <audio src="/song.mp3" crossorigin="anonymous">
await client.publishMusic(song, { volume: 0.8 }); // call it from a click
await song.play();
client.setMusicVolume(0.4); // for the audience
await client.setMusicEnabled(false); // music off, host still talking
await client.setMicEnabled(false); // mic off, music still playing
await client.stopMusic();
The host keeps hearing the music while it is on air; pass { monitor: false } to send it without playing it locally. A song served from another origin must send CORS headers and be loaded with crossorigin="anonymous", or the browser gives the page silence, and silence is what gets published.
Step 3: let listeners hear it, and turn it down
Every SDK receives the music. In the browser it arrives as a second audio track, and source says which is which:
client.on("track", ({ identity, kind, source, track }) => {
if (source === "music") {
musicAudio.srcObject = new MediaStream([track]); // its own element, its own volume
} else {
attach(identity, kind, track);
}
});
client.on("trackMuted", ({ source, paused }) => {
if (source === "music") showMusicPaused(paused);
});
musicAudio.muted = true; // "mute the music" for this viewer only
In a Flutter app, remote sound plays by itself; give the music its own volume through its track:
client.onTrack.listen((t) {
if (t.isMusic) setState(() => musicTrack = t.track);
});
client.onTrackMuted.listen((m) {
if (m.source == 'music') setState(() => musicPlaying = !m.paused);
});
await Helper.setVolume(0.3, musicTrack); // flutter_webrtc: quieter music for this listener
musicTrack.enabled = false; // or muted for this listener; the host's voice is untouched
source is also on each entry of producers in the join result, so a listener who joins after the music started is told too. The React SDK lists the music track in useRemoteTracks with source: "music".
Hosts on phones
- Flutter has the same calls:
publishMusic(musicStream)with aMediaStreamthat holds the audio, thensetMusicEnabledandstopMusic. What differs is where the stream comes from: on Android and iOS the WebRTC plugin the SDK builds on does not expose audio your app is playing as a track, so a clean music track needs a native audio source in your app. - Android: the Android SDK plays a file with
publishMusic(MusicPlayer(context).apply { play(uri) })and mixes it into the microphone before encoding, so it never echoes, and tells the service the microphone is carrying music, so it is billed as the music add-on like a music track. - React Native apps receive music; publishing it there is not available and rejects with
music-unavailable.
Pausing and stopping
setMusicEnabled(false) pauses the music at the source and tells every listener, who get trackMuted with source set to music; setMusicEnabled(true) brings it back, and stopMusic() takes it off air. The microphone's switch is separate, so a host can stay quiet while a song plays.
What it costs
Music add-on: ₹10 (≈ $0.11) per 1,000 participant-minutes while music plays, for each participant on standard or HD voice. Included with video: a participant on video never pays it.Prices are in Indian rupees; dollar figures are approximate, at ₹95 per US dollar on 24 October 2026, for orientation only. You are billed in rupees.
The add-on is per participant. While a track plays unmuted, the host and every listener on standard or HD voice pay it on top of their voice rate, for those seconds; with the music paused or stopped, nobody pays it. A participant on video pays the video rate and never the add-on, but in a project with video on, a voice-only participant who hears the music pays it. Turning the music down in a listener's player changes nothing, because the track still arrives; pausing it with setMusicEnabled(false) stops the add-on for everyone at once. Sessions still on minute billing never pay it.
A room of a host and nine listeners on standard voice for half an hour costs this before any music:
10 people × 30 minutes = 300 participant-minutes
300 participant-minutes × 39 ÷ 1,000 = 11.7 credits, ₹11.70 (≈ $0.12) at today's rate
Standard Voice: 39 credits per 1,000 participant-minutes. Billed per second, so a 7½-minute call costs 7½ minutes.
If music plays for the whole half hour, the same 300 participant-minutes also pay the music add-on; Usage and billing works that session through. The add-on shows as its own Music add-on line on Wallet > Usage and in each session's detail.
In the browser, music adds a 128 kbps stereo track to the host's upload and to each listener's download, so a host on a weak connection should check their upload before a long set. Chat in the same room is not charged; see voice chat rooms for the rest of the room: the stage, seats, raise hand and moderation.
The songs themselves
VoltKit carries the audio; the rights to the songs are your app's and your hosts' to arrange. The acceptable use policy forbids streaming anything you have no right to use, music included.
Frequently asked questions
Can a host play music in a voice chat room without echo?
Yes. publishMusic takes the song from inside the app, so it never passes through the speakers and the microphone, where echo cancellation would remove most of it. In the browser it goes out as its own 128 kbps stereo track beside the host's voice.
Who pays for music in a voice chat room?
Each participant on standard or HD voice pays the music add-on on top of their voice rate, for the seconds a track plays unmuted: the host and every listener alike. A participant on video never pays it. It is per participant, so in a project with video on, a voice-only participant who hears the music pays the add-on.
Do I have to switch anything on before a host can play music?
Yes, in a voice project: turn on the Music add-on under the project's Settings, Media and quality. New projects start with it off. A project with video on may always publish music. Without either, publishMusic is refused with the code media-disabled and the microphone is untouched.
Can listeners turn the music down?
Yes. Music arrives as a track of its own, so each listener's app can lower or mute it without losing the host's voice. That changes nothing on the bill, because the track still arrives. When the host switches the music off with setMusicEnabled(false), it stops for everyone and so does the add-on.
Can a phone app play music to the room?
A Flutter app publishes music with the same publishMusic call, given a stream that holds the audio; on Android and iOS that stream needs a native audio source in your app today. The Android SDK mixes in-app music into the microphone before encoding and tells the service it is music, so it is billed as the music add-on like a music track. React Native apps receive music but cannot publish it.
Who is responsible for the rights to the songs?
Your app and its hosts. VoltKit carries the audio; the acceptable use policy forbids streaming anything you have no right to use, music included.