pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.45k stars 759 forks source link

How to record screen on android #1508

Open MinhMinh8722 opened 6 days ago

MinhMinh8722 commented 6 days ago

Can you show me where the code for recording the screen and saving the file into local storage? Thanks!!! 🙏

pedroSG94 commented 6 days ago

Hello,

If you want record the screen you can use this example: https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/screen

If you want record instead of stream you can replace isStreaming to isRecording, startStream to startRecord and stopStream to stopRecord.

isStreaming: https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/screen/ScreenService.kt#L112 To:

return genericStream.isRecording

startRecord: https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/screen/ScreenService.kt#L155 To:

    if (!genericStream.isRecording) genericStream.startRecord(filePath)

And stop record: https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/screen/ScreenService.kt#L119 To:

  fun stopStream() {
    if (genericStream.isRecording) {
      genericStream.stopRecord()
      notificationManager?.cancel(notifyId)
    }
  }

In ScreenActivity you will need replace the stream url provided in the startRecord to a valid file path

MinhMinh8722 commented 5 days ago

Thanks for your answer. And can I draw a watermark on surfaceview?

pedroSG94 commented 5 days ago

You can use filters: https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/utils/FilterMenu.kt#L211 You can get glInterface with:

genericStream.getGlInterface()