🎥 Source Configuration
Setting Audio & Video Sources
You can dynamically set or change the audio and video sources in your Streamer object by passing a source factory to setAudioSource and setVideoSource.
val streamer = SingleStreamer(context)
// Set microphone and camera sources
streamer.setAudioSource(MicrophoneSourceFactory())
streamer.setVideoSource(CameraSourceFactory())
Available Source Factories
You can pass any of the following built-in factories to setAudioSource() or setVideoSource() depending on your needs:
Audio:
MicrophoneSourceFactory(Standard device microphone)MediaProjectionAudioSourceFactory(Screen audio recording)
Video:
CameraSourceFactory(Standard device camera)MediaProjectionVideoSourceFactory(Screen video recording)BitmapSourceFactory(Stream a static image)
If you need to stream from a source that isn't provided out of the box, check out the Creating Custom Sources guide.
Helpful Source Extensions
StreamPack provides convenient extension functions to quickly configure specific sources without needing to cast them manually:
// Switch to a specific camera ID (often "0" for back, "1" for front but you should always query the camera list)
streamer.setCameraId("0")
// Set a static image/bitmap as the video source (useful for "stream starting soon" screens)
val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.holding_image)
streamer.setBitmap(bitmap)
On-the-fly control
On a streamer object, you can retrieve the source object and cast it to the specific source:
audioSource (an IAudioSource) or videoSource (an IVideoSource). This allows you to have access to specific hardware configuration on the fly while streaming.
val streamer = cameraSingleStreamer(context)
// Audio source
streamer.audioInput.sourceFlow.filterNotNull().collect {
if (this is IAudioRecordSource) {
// Specific audio source configuration
// Example: IAudioRecordSource specific configuration has `addEffect` method
addEffect(AudioEffect.EFFECT_TYPE_AEC)
}
}
// Video source
streamer.videoInput.sourceFlow.filterNotNull().collect {
if (this is ICameraSource) {
// Specific video source configuration
// Example: ICameraSource specific configuration has `settings` member.
settings.flash.setIsEnable(true)
settings.stabilization.setIsEnableOptical(false)
}
}
Here is how to cast the sources: