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

How to pause the recording? #5

Closed
FazliMolaJan opened this issue Nov 13, 2019 · 12 comments
Closed

How to pause the recording? #5

FazliMolaJan opened this issue Nov 13, 2019 · 12 comments
Labels
feature request Enquiry about a feature

Comments

@FazliMolaJan
Copy link

Like I want to pause the screen recording while it is recording and restart it again from there? How I can do it?

@HBiSoft HBiSoft added the feature request Enquiry about a feature label Nov 14, 2019
@HBiSoft
Copy link
Owner

HBiSoft commented Nov 14, 2019

I will implement this soon.

@HBiSoft
Copy link
Owner

HBiSoft commented Jan 14, 2020

The only way I was able to do this is to create different video files each time the video is paused/resumed and then merge them together.

There is a library called Mp4Parser that can merge the files.

Implement the library into your project then you can merge the files like this:

public static boolean mergeMediaFiles(boolean isAudio, String sourceFiles[], String targetFile) {
    try {
        String mediaKey = isAudio ? "soun" : "vide";
        List<Movie> listMovies = new ArrayList<>();
        for (String filename : sourceFiles) {
            listMovies.add(MovieCreator.build(filename));
        }
        List<Track> listTracks = new LinkedList<>();
        for (Movie movie : listMovies) {
            for (Track track : movie.getTracks()) {
                if (track.getHandler().equals(mediaKey)) {
                    listTracks.add(track);
                }
            }
        }
        Movie outputMovie = new Movie();
        if (!listTracks.isEmpty()) {
            outputMovie.addTrack(new AppendTrack(listTracks.toArray(new Track[listTracks.size()])));
        }
        Container container = new DefaultMp4Builder().build(outputMovie);
        FileChannel fileChannel = new RandomAccessFile(String.format(targetFile), "rw").getChannel();
        container.writeContainer(fileChannel);
        fileChannel.close();
        return true;
    }
    catch (IOException e) {
        Log.e(LOG_TAG, "Error merging media files. exception: "+e.getMessage());
        return false;
    }
}

You can also use FFmpeg to merge the files.


I will be closing this issue because this can be implemented by the developer instead of adding it to the library.

@HBiSoft HBiSoft closed this as completed Jan 14, 2020
@chiragthummar
Copy link

@HBiSoft i have tried to merge video using above code but not able to do because mp4parser lib gives error.
will you help me in merging video with example.

@HBiSoft
Copy link
Owner

HBiSoft commented Aug 31, 2020

@chiragthummar
I just did a test and it is working perfectly.
What error are you getting?

@chiragthummar
Copy link

chiragthummar commented Aug 31, 2020

its give me error like below
file is there but it show me following error

W/System.err: java.io.FileNotFoundException: /storage/emulated/0/HD2020-08-31-18-55-29.mp4 (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:231)
        at java.io.FileInputStream.<init>(FileInputStream.java:165)
        at com.googlecode.mp4parser.FileDataSourceImpl.<init>(FileDataSourceImpl.java:20)
W/System.err:     at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38)
        at com.qp.mp4parserdemo.Mp4ParserUtils.mergeVideo(Mp4ParserUtils.java:36)
        at com.qp.mp4parserdemo.MainActivity$1.onClick(MainActivity.java:37)
        at android.view.View.performClick(View.java:6733)
        at android.view.View.performClickInternal(View.java:6691)
        at android.view.View.access$3400(View.java:802)
        at android.view.View$PerformClick.run(View.java:26499)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:226)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7178)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

@chiragthummar
Copy link

chiragthummar commented Aug 31, 2020

and sometime it give this error as well.

W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.coremedia.iso.boxes.MovieBox.getBoxes(java.lang.Class)' on a null object reference
W/System.err:     at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:51)
        at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38)
        at com.hbisoft.hbrecorderexample.Mp4ParserUtils.mergeVideo(Mp4ParserUtils.java:34)
        at com.hbisoft.hbrecorderexample.MainActivity$2.onClick(MainActivity.java:223)
        at android.view.View.performClick(View.java:6733)
        at android.view.View.performClickInternal(View.java:6691)
        at android.view.View.access$3400(View.java:802)
        at android.view.View$PerformClick.run(View.java:26499)
        at android.os.Handler.handleCallback(Handler.java:873)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:226)
        at android.app.ActivityThread.main(ActivityThread.java:7178)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

@chiragthummar
Copy link

will you please give me full example of merging video ?

@HBiSoft
Copy link
Owner

HBiSoft commented Sep 1, 2020

@chiragthummar
I will provide an example within the next 2-3 hours.

I was thinking of creating a repo demonstrating this for future developers.

@chiragthummar
Copy link

thanks

@chiragthummar
Copy link

Hello
does below code work in android Q or not ?

if (mMediaRecorder != null) {
            mMediaRecorder.pause();
        }

HBiSoft added a commit that referenced this issue Sep 2, 2020
@HBiSoft
Copy link
Owner

HBiSoft commented Sep 2, 2020

@chiragthummar
It is now available in 0.1.13.

You can pause the recording by calling:

hbRecording.pauseScreenRecording();

You can resume the recording by calling:

hbRecording.resumeScreenRecording();

This is only available for devices running 24> and it is important to check if the recording has started or was paused using hbRecorder.isBusyRecording(); and hbrecorder.isRecordingPaused();.

Hope you find this helpful.

@chiragthummar
Copy link

Thank you so much for your quick answer.

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

No branches or pull requests

3 participants