Trim the video by adjusting starting point and ending point in Android
Trim the video by adjusting starting point and ending point in Android.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
...
implementation 'com.github.Ahmedbadereldin:Video-Trimmer-Android:1.0.4'
}
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<application
...
android:requestLegacyExternalStorage="true"
...
>
...
<activity
android:name=".YourActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<!-- <data android:mimeType="*/*" /> -->
<data android:mimeType="video/*" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
<activity
android:name=".VideoTrimmerActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.SlidrActivityTheme"
android:windowSoftInputMode="adjustPan" />
...
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Open VideoTrimmerActivity
if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) { //recive
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
// MEDIA GALLERY
String path = getPath(selectedImageUri);
Uri uriFile = Uri.fromFile(new File(path));
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uriFile.toString());
Log.d(TAG, "onActivityResult: " + fileExtension);
if (fileExtension.equalsIgnoreCase("MP4")) {
File file = new File(path);
if (file.exists()) {
startActivityForResult(new Intent(YourActivity.this, VideoTrimmerActivity.class).putExtra("EXTRA_PATH", path), VIDEO_TRIM);
overridePendingTransition(0, 0);
} else {
Toast.makeText(NewPostActivity.this, "Please select proper video", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, getString(R.string.file_format) + " ," + fileExtension, Toast.LENGTH_SHORT).show();
}
}
}
// ForResult from VideoTrimmerActivity
if (requestCode == VIDEO_TRIM) {
if (resultCode == RESULT_OK) {
if (data != null) {
String videoPath = data.getExtras().getString("INTENT_VIDEO_FILE");
File file = new File(videoPath);
Log.d(TAG, "onActivityResult: " + file.length());
pathPostImg = videoPath;
Glide.with(this)
.load(pathPostImg)
.into(postImg);
postImgLY.setVisibility(View.VISIBLE);
}
}
}
}
### RxJava, RxAndroid for media-picker-android library
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
### mp4parser
-keep class * implements com.coremedia.iso.boxes.Box {* ; }
-dontwarn com.coremedia.iso.boxes.*
-dontwarn com.googlecode.mp4parser.authoring.tracks.mjpeg.**
-dontwarn com.googlecode.mp4parser.authoring.tracks.ttml.**
For any inquiries or clarifications, you can contact me via e-mail. Just send an email to [email protected].