Is there any way to streaming just white canvas board with audio mute/unmute feature? #1980
Replies: 10 comments 2 replies
-
|
Hello, Yes, you can stream a canvas in realtime using StreamBase classes (GenericStream, RtmpStream, etc). You will have to modify this class to work as you want: Currently that class draw a bitmap in each frame but you can modify it to allow access to the canvas, for example: class CanvasSource(private val drawCanvas: (Canvas) -> Unit): VideoSource() {
@Volatile
private var running = false
private var job: Job? = null
private var surface: Surface? = null
override fun create(width: Int, height: Int, fps: Int, rotation: Int): Boolean {
return true
}
override fun start(surfaceTexture: SurfaceTexture) {
surfaceTexture.setDefaultBufferSize(width, height)
surface = Surface(surfaceTexture)
running = true
job = CoroutineScope(Dispatchers.IO).launch {
while (running) {
try {
val canvas = surface?.lockCanvas(null)
canvas?.let { drawCanvas(canvas) }
surface?.unlockCanvasAndPost(canvas)
} catch (_: Exception) { }
//sleep to emulate fps
delay(1000 / fps.toLong())
}
}
}
override fun stop() {
running = false
runBlocking { job?.cancelAndJoin() }
surface?.release()
surface = null
}
override fun release() {}
override fun isRunning(): Boolean = running
}Now you can use the new VideoSource and add your own code in the callback: val genericStream = GenericStream(requireContext(), this,
videoSource = CanvasSource { canvas -> canvas.drawColor(Color.WHITE) },
audioSource = MicrophoneSource()
)The callback is called in each frame, you can modify the result as you want |
Beta Was this translation helpful? Give feedback.
-
|
Hello @pedroSG94 Thank you for the response. I am trying with your suggestion
I am not getting Proper
|
Beta Was this translation helpful? Give feedback.
-
|
Hello, That is expected, the problem is related with the scale and/or the aspect ratio of your original view. val bitmap = view.drawToBitmap() //get bitmap from your original view
val matrix = Matrix()
//width and height of the stream
val scaleX = width.toFloat() / bitmap.width
val scaleY = height.toFloat() / bitmap.height
if (rotation == 0 || rotation == 180) { //scale depend of vertical or horizontal stream
matrix.setScale(scaleX, scaleY)
} else {
matrix.setScale(scaleY, scaleX)
}
canvas.drawBitmap(bitmap, matrix, null) |
Beta Was this translation helpful? Give feedback.
-
|
Other possible solution and faster (to get more fps). You can use your original view with the same aspect ratio than the stream and create a method to draw into the canvas but with the paths values scaled. |
Beta Was this translation helpful? Give feedback.
-
|
I tried with original view's dimension and it is working fine, but my streaming not get updated when canvas re-draw as user draw something
|
Beta Was this translation helpful? Give feedback.
-
|
Hello , |
Beta Was this translation helpful? Give feedback.
-
|
Hello, It is working fine for me. I let you here a patch to apply in the master branch of my app example. You only need:
|
Beta Was this translation helpful? Give feedback.
-
|
Hello @pedroSG94 Brother, I tried in your example part and i am not getting streaming using https://github.com/sallar/mac-local-rtmp-server Screen.Recording.2025-11-20.at.9.59.18.AM.1.mp4 |
Beta Was this translation helpful? Give feedback.
-
|
Hello, I was doing tests and maybe the problem is related with VLC in macOS. I don't know the reason but it is freezed. Should be fine using it on Linux or Windows |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the update! |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Hello Brother,
Is there any way to streaming just white canvas board with audio mute/unmute feature?
I want streaming white board canvas using your library
Beta Was this translation helpful? Give feedback.
All reactions