Audio Streaming
ConoStream SDK provides high-quality audio streaming with automatic noise cancellation, echo reduction, and adaptive bitrate. This guide covers how to publish and subscribe to audio streams.
Publishing Audio
To publish your microphone audio to the room:
// After connecting to the room
manager.connect(serverUrl, token, new ConoStreamEventListener() {
@Override
public void onConnected() {
// Publish microphone audio
manager.publishMicrophone();
}
});
Mute/Unmute Microphone
// Mute microphone
manager.muteMicrophone(true);
// Unmute microphone
manager.muteMicrophone(false);
// Check if muted
boolean isMuted = manager.isMicrophoneMuted();
Using ConoStreamAudioHelper
For more advanced audio room features (like co-hosting), use the
ConoStreamAudioHelper class:
public class AudioLiveActivity extends AppCompatActivity {
private ConoStreamAudioHelper audioHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ConoStreamManager manager = getConoStreamManager();
// Initialize audio helper
audioHelper = new ConoStreamAudioHelper(manager, this);
// Set event callback
audioHelper.setEventCallback(new ConoStreamEventCallback() {
@Override
public void onAudioTrackPublished() {
Log.d("Audio", "Audio track published successfully");
}
@Override
public void onRemoteAudioTrackSubscribed(String participantId) {
Log.d("Audio", "Subscribed to: " + participantId);
}
@Override
public void onParticipantJoined(String participantId, String name) {
Log.d("Audio", name + " joined the room");
}
@Override
public void onParticipantLeft(String participantId, String name) {
Log.d("Audio", name + " left the room");
}
});
}
}
Joining as Host
When the user is the host of an audio room:
// Join as host - will automatically publish audio
audioHelper.joinAsHost(serverUrl, token, channelName);
Joining as Audience
When the user is just listening (not publishing audio):
// Join as audience - listen only
audioHelper.joinAsAudience(serverUrl, token, channelName);
Upgrading to Co-Host
When an audience member becomes a co-host:
// Upgrade audience to co-host (starts publishing audio)
audioHelper.upgradeToCoHost();
Audio Configuration
ConoStream automatically configures optimal audio settings, but you can customize:
Speaker vs Earpiece
// Force audio through speaker (loudspeaker mode)
manager.configureAudioForSpeaker();
// Audio settings applied:
// - AudioManager.MODE_NORMAL (not call mode)
// - STREAM_MUSIC (not voice call stream)
// - Output: Speaker, Bluetooth, Wired Headset
Important: Call configureAudioForSpeaker() after
the room is connected, not before. The SDK may reset audio settings during connection.
Handling Remote Audio
Remote audio tracks are automatically played when subscribed. You don't need to manually handle playback. However, you can receive events when remote audio is available:
audioHelper.setEventCallback(new ConoStreamEventCallback() {
@Override
public void onRemoteAudioTrackSubscribed(String participantId) {
// Remote audio is now playing
Log.d("Audio", "Now hearing: " + participantId);
}
@Override
public void onRemoteAudioTrackUnsubscribed(String participantId) {
// Remote audio stopped
Log.d("Audio", "No longer hearing: " + participantId);
}
});
Cleanup
Always clean up when leaving the audio room:
@Override
protected void onDestroy() {
super.onDestroy();
if (audioHelper != null) {
audioHelper.leaveRoom();
audioHelper = null;
}
}
Best Practices
- Always request
RECORD_AUDIOpermission before publishing - Call
configureAudioForSpeaker()after connection for speaker output - Handle
onDestroy()to properly leave the room - Use
ConoStreamAudioHelperfor rooms with co-hosting features