Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.itsnothingg:EasyScreenRecorder:1.0.0'
}
dependencies {
implementation("com.github.itsnothingg:EasyScreenRecorder:1.0.0")
}
<dependency>
<groupId>com.github.itsnothingg</groupId>
<artifactId>EasyScreenRecorder</artifactId>
<version>1.0.0</version>
</dependency>
libraryDependencies += "com.github.itsnothingg" % "EasyScreenRecorder" % "1.0.0"
:dependencies [[com.github.itsnothingg/EasyScreenRecorder "1.0.0"]]
Library that helps you to implement screen recorder(with sound) functionality easily
From the sample :
First Add jitpack.io on yout root build.gradle
:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
jcenter()
}
}
Add the following dependency on your app's build.gradle
:
compile 'com.github.itsnothingg:EasyScreenRecorder:1.0.0'
First of all, make sure you have these permissions granted in order for this lib to work.
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO
First thing you'll have to do is to grant media projection permission by using the following code
MediaProjectionManager mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(), REQUEST_CODE);
this will call permission dialog, and return result on onActivityResult
Then on onActivityResult
initialize EasyScreenRecorder instance
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
if (resultCode != RESULT_OK) {
return;
}
MediaProjection mediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data);
EasyScreenRecorder mScreenRecorder = new EasyScreenRecorder([yourContext], [pathToYourMP4File], mediaProjection);
}
}
Now you are ready to use these functions
mScreenRecorder.start(); // start recording
mScreenRecorder.pause(); // pause recording
mScreenRecorder.resume(); // resume recording
mScreenRecorder.stop(); // finish and release recording
File videoFile = new File(mScreenRecorder.getPath()); // after recording has stopped, you can play with your file.
There are few thing you can customize like:
mScreenRecorder.recordAudio(false); // don't record audio
mScreenRecorder.setFrameRate(30); // set frame rate to 30. (default is 25)
mScreenRecorder.setBitrate(800 * 1000); // change bitrate (default is auto-calculated)
please take a look at sample module for more details.
copyright of java files under encoder
package belongs to saki t_saki@serenegiant.com
most of the sources are from https://github.com/saki4510t/AudioVideoRecordingSample repo.
it's great repo so please take a look if you are interested in MediaCodec/MediaMuxer.