Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause status on RecordController.Listener #1447

Open
altunbayrakergun opened this issue Mar 29, 2024 · 3 comments
Open

Pause status on RecordController.Listener #1447

altunbayrakergun opened this issue Mar 29, 2024 · 3 comments

Comments

@altunbayrakergun
Copy link

Hello Pedro,
I am developing an application where I stream along with video recording. In this application, the user can mark certain periods of the video and use it later. In order to show this time during the flow, I use a different timer and increase it every second. Therefore, I need the recorded video duration to also be exactly equal to the time information I advance. In order to do this, I need to capture the exact moments when the video recording starts, the exact moments it pauses, or the exact moments the recording ends. Using RecordListener, I can capture the exact moment when video recording starts with the RECORDING status. However, the PAUSED status that is triggered when I pause the video recording, is not triggering at the exact moment. The recording continues 2 or more seconds and then pauses. Therefore, the time variable I manage does not match the actual video duration. Serious shifts occur when rendering the moments marked by the user.

I need to clearly capture the moment when video recording is paused or stopped completely. Is there any way to do this?

@pedroSG94
Copy link
Owner

Hello,

When you pause/resume the video, the status is send inmediately:
https://github.com/pedroSG94/RootEncoder/blob/master/library/src/main/java/com/pedro/library/base/recording/BaseRecordController.java#L67

So, I don't understand that 2 seconds.
How are you checking that time? do you have a code example to reproduce?

@pedroSG94
Copy link
Owner

pedroSG94 commented Mar 29, 2024

Anyway you can try this.
You can access to internal ts this way:

1- Create a custom recordController:

class ExtendedRecordController: AndroidMuxerRecordController() {

  //in micro seconds
  fun getVideoTs(): Long {
    return this.videoInfo.presentationTimeUs
  }

  //in micro seconds
  fun getAudioTs(): Long {
    return this.audioInfo.presentationTimeUs
  }
}

2- Set record controller:

val recordController = ExtendedRecordController()
genericStream.setRecordController(recordController)

3 - Get ts on Pause callback:

genericStream.startRecord(path) {
  when (it) {
    RecordController.Status.STARTED -> TODO()
    RecordController.Status.STOPPED -> TODO()
    RecordController.Status.RECORDING -> TODO()
    RecordController.Status.PAUSED -> {
      recordController.getVideoTs()
      recordController.getAudioTs()
    }
    RecordController.Status.RESUMED -> TODO()
  }
}

@altunbayrakergun
Copy link
Author

altunbayrakergun commented Mar 30, 2024

I'm not sure exactly why there is such a shift. I start and stop my own timer when the RecordController.Listener event occurs. But when I look at the recorded video, I see that it is 2 seconds or more long. I tested on Samsung Note10+, Redmi Note 9 Pro, Xiaomi 10 Pro devices. I had the same problem with all of them.
My sample code is as follows.
rtmpCamera1.startRecord(Paths.get(mVideoPath, this.mVideoFile).toAbsolutePath().toString(), new RecordController.Listener() {

                        @Override
                        public void onStatusChange(RecordController.Status status) {
                            if(status == RecordController.Status.RECORDING){
                                setTimerOnStream(true);
                            }else if(status == RecordController.Status.STOPPED || status == RecordController.Status.PAUSED){
                                setTimerOnStream(false);
                            }
                        }

}

When the Pause or Stop actions are triggered, I stop my own timer. But the video recording does not stop immediately, it continues recording. For this reason, there is a difference of 2-3 seconds between my own timer and the real video.

By the way, I'll try your suggestion.
Thank you for all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants