Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iNuman/ca1777a0f76769dc1faaf279bc3461ab to your computer and use it in GitHub Desktop.

Select an option

Save iNuman/ca1777a0f76769dc1faaf279bc3461ab to your computer and use it in GitHub Desktop.
package com.arham.photo.video.editor.activities;
import android.app.ProgressDialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Images.Media;
import android.provider.MediaStore.Video;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.ItemTouchHelper.Callback;
import com.arham.photo.video.editor.AdsHandling;
import com.arham.photo.video.editor.NativeAd.NativeAdFragment;
import com.arham.photo.video.editor.NativeAd.NativeAdFragment2;
import com.arham.photo.video.editor.share.Share;
import com.arham.photo.video.editor.share.SharedPrefs;
import com.arham.photo.video.editor.util.AdPreManager;
import com.arham.photo.video.editor.util.CustomUtils;
import com.arham.photo.video.editor.util.FileUtils;
import com.arham.photo.video.editor.util.GlobalData;
import com.arham.photo.video.movie.maker.song.slideshow.editor.R;
import com.arthenica.mobileffmpeg.ExecuteCallback;
import com.arthenica.mobileffmpeg.FFmpeg;
import com.google.android.gms.ads.AdListener;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.analytics.FirebaseAnalytics.Param;
import org.florescu.android.rangeseekbar.RangeSeekBar;
import org.florescu.android.rangeseekbar.RangeSeekBar.OnRangeSeekBarChangeListener;
import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import static com.arham.photo.video.editor.AudioProject.Activities.Formateconvert.PATH_OF_VIDEO_TO_DELETE;
import static com.arham.photo.video.editor.AudioProject.Activities.Formateconvert.SHARED_PREFS_NAME;
import static com.arham.photo.video.editor.util.FileUtils.APP_DIRECTORY;
import static com.arham.photo.video.editor.util.PathUtil.getPath;
import static com.arthenica.mobileffmpeg.Config.RETURN_CODE_CANCEL;
import static com.arthenica.mobileffmpeg.Config.RETURN_CODE_SUCCESS;
public class FastMotion extends AppCompatActivity {
private static final String FILEPATH = "filepath";
private static final String POSITION = "position";
private static final int REQUEST_TAKE_GALLERY_VIDEO = 100;
private static final String TAG = "ffnet";
private FrameLayout adContainerView;
Toolbar toolbar;
/* access modifiers changed from: private */
public int choice = 0;
/* access modifiers changed from: private */
public int duration;
private FFmpeg ffmpeg;
/* access modifiers changed from: private */
public String filePath;
private Context mContext;
/* access modifiers changed from: private */
public LinearLayout mainlayout;
/* access modifiers changed from: private */
public ProgressDialog progressDialog;
/* access modifiers changed from: private */
public Runnable r;
/* access modifiers changed from: private */
public RangeSeekBar rangeSeekBar;
public LinearLayout l2;
private Uri selectedAudioUri;
/* access modifiers changed from: private */
public Uri selectedVideoUri;
private int stopPosition;
/* access modifiers changed from: private */
public TextView tvLeft;
/* access modifiers changed from: private */
public TextView tvRight;
/* access modifiers changed from: private */
public VideoView videoView;
private MyApplication application;
/* access modifiers changed from: protected */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fastmton);
application = MyApplication.getInstance();
toolbar=findViewById(R.id.toolbar1);
progressDialog=new ProgressDialog(this);
if (toolbar != null) {
// you can safely invoke methods on the Toolbar
setSupportActionBar(toolbar);
Drawable d=getResources().getDrawable(R.drawable.custom_color);
getSupportActionBar().setBackgroundDrawable(d);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Fast Motion");
} else {
// Toolbar is null, handle it
}
this.mContext = this;
this.adContainerView = findViewById(R.id.ad_view_container);
CustomUtils customUtils;
customUtils = new CustomUtils(this);
boolean connected=customUtils.isConnectingToInternet();
if (connected)
{
boolean inAppStatus= AdPreManager.getInstance(this).getProductPurachase();
if (!inAppStatus) {
getFragmentManager().beginTransaction().add(R.id.fast_motion_frameLayout, new NativeAdFragment2()).commit();
// FrameLayout frameLayout=findViewById(R.id.myVideo_frameLayout);
// LoadAds.getInstance(this).loadAdaptiveBanner(MyVideoActivity.this,frameLayout);
}
//
if (application.requestNewInterstitial()) {
application.mInterstitialAd.setAdListener(null);
application.mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
application.LoadAds();
}
});
} else {
application.LoadAds();
}
}
TextView tvInstructions = (TextView) findViewById(R.id.tvInstructions);
tvInstructions.setEllipsize(TextUtils.TruncateAt.MARQUEE);
tvInstructions.setMarqueeRepeatLimit(-1);
tvInstructions.setSingleLine(true);
tvInstructions.setSelected(true);
Button uploadVideo = findViewById(R.id.uploadVideo);
Button fastmtn = findViewById(R.id.fstmtn);
this.mainlayout = findViewById(R.id.mainlayout);
this.tvLeft = findViewById(R.id.tvLeft);
this.tvRight = findViewById(R.id.tvRight);
this.videoView = findViewById(R.id.videoView);
this.rangeSeekBar = findViewById(R.id.rangeSeekBar);
this.l2 = findViewById(R.id.l2);
this.progressDialog = new ProgressDialog(this);
this.progressDialog.setTitle("Processing...");
this.progressDialog.setCancelable(true);
this.rangeSeekBar.setEnabled(true);
uploadVideo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (VERSION.SDK_INT >= 23) {
getPermission();
} else {
uploadVideo();
}
}
});
fastmtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
choice = 5;
if (selectedVideoUri != null) {
try {
fastmotionexecute(rangeSeekBar.getSelectedMinValue().intValue() * 1000, rangeSeekBar.getSelectedMaxValue().intValue() * 1000);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Snackbar.make(mainlayout, "Please upload a video", 4000).show();
}
}
});
}
/* access modifiers changed from: private */
public void getPermission() {
String[] params = null;
String writeExternalStorage = "android.permission.WRITE_EXTERNAL_STORAGE";
String readExternalStorage = "android.permission.READ_EXTERNAL_STORAGE";
int hasWriteExternalStoragePermission = ActivityCompat.checkSelfPermission(this, writeExternalStorage);
int hasReadExternalStoragePermission = ActivityCompat.checkSelfPermission(this, readExternalStorage);
List<String> permissions = new ArrayList<>();
if (hasWriteExternalStoragePermission != 0) {
permissions.add(writeExternalStorage);
}
if (hasReadExternalStoragePermission != 0) {
permissions.add(readExternalStorage);
}
if (!permissions.isEmpty()) {
params = permissions.toArray(new String[permissions.size()]);
}
if (params == null || params.length <= 0) {
uploadVideo();
} else {
ActivityCompat.requestPermissions(this, params, 100);
}
}
/* access modifiers changed from: private */
public void fastmotionexecute(int startMs, int endMs) throws Exception {
String yourRealPath = getPath(this, this.selectedVideoUri);
// StringBuilder sb4 = new StringBuilder();
// sb4.append("startTrim: src: ");
// sb4.append(yourRealPath);
// String sb5 = sb4.toString();
// String str = TAG;
// Log.d(str, sb5);
//-----------------------------
StringBuilder sb = new StringBuilder();
sb.append(APP_DIRECTORY);
File moviesDir = new File(sb.toString());
if (!moviesDir.exists()) {
moviesDir.mkdirs();
}
// if (!SAVE_DIRECTORY.exists()) {
// SAVE_DIRECTORY.mkdirs();
// }
// StringBuilder sb = new StringBuilder();
// sb.append(Environment.getExternalStorageDirectory().getAbsolutePath());
// sb.append(GlobalData.path_video);
// File moviesDir = new File(sb.toString());
// if (!moviesDir.exists()) {
// moviesDir.mkdirs();
// }
String filePrefix = GlobalData.FAST_MOTION + System.currentTimeMillis();
String fileExtn = ".mp4";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ContentValues valuesvideos = new ContentValues();
valuesvideos.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM + GlobalData.path_video);
valuesvideos.put(MediaStore.Video.Media.TITLE, filePrefix);
valuesvideos.put(MediaStore.Video.Media.DISPLAY_NAME, filePrefix + fileExtn);
valuesvideos.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
valuesvideos.put(MediaStore.Video.Media.DATE_ADDED, System.currentTimeMillis() / 1000);
valuesvideos.put(MediaStore.Video.Media.DATE_TAKEN, System.currentTimeMillis());
Uri uri = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, valuesvideos);
File file = new File(getPath(this, uri));
filePath = file.getAbsolutePath();
} else {
StringBuilder sb2 = new StringBuilder();
sb2.append(filePrefix);
sb2.append(fileExtn);
File dest = new File(moviesDir, sb2.toString());
int fileNo = 0;
while (dest.exists()) {
fileNo++;
StringBuilder sb3 = new StringBuilder();
sb3.append(filePrefix);
sb3.append(fileNo);
sb3.append(fileExtn);
dest = new File(moviesDir, sb3.toString());
}
filePath = dest.getAbsolutePath();
}
String str2 = "-map";
Log.d(TAG, "fastmotionexecute: "+filePath);
GlobalData.PATH_ = yourRealPath;
SharedPreferences preferences = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
preferences.edit().putString(PATH_OF_VIDEO_TO_DELETE, filePath).apply();
/*
* TODO FastMotion: This command will trim video and convert it to fast motion
* */
String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", yourRealPath, "-t", "" + (endMs - startMs) / 1000, "-filter_complex", "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]", str2, "[v]", str2, "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", filePath};
execFFmpegBinary(complexCommand);
// execFFmpegBinary(new String[]{"-y", "-i", yourRealPath, "-filter_complex", "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]", "-map", "[v]", str2, "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", filePath});
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return super.onSupportNavigateUp();
}
/* access modifiers changed from: private */
public void uploadVideo() {
try {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction("android.intent.action.GET_CONTENT");
startActivityForResult(Intent.createChooser(intent, "Select Video"), 100);
} catch (Exception e) {
}
}
/* access modifiers changed from: protected */
public void onPause() {
super.onPause();
this.stopPosition = this.videoView.getCurrentPosition();
this.videoView.pause();
}
/* access modifiers changed from: protected */
public void onResume() {
super.onResume();
this.videoView.seekTo(this.stopPosition);
this.videoView.start();
}
/* access modifiers changed from: protected */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == -1 && requestCode == 100) {
this.selectedVideoUri = data.getData();
this.videoView.setVideoURI(this.selectedVideoUri);
this.videoView.start();
Animation blinkAnim = AnimationUtils.loadAnimation(this, R.anim.blink2);
//rangeSeekBar.startAnimation(blinkAnim);
l2.startAnimation(blinkAnim);
this.videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
duration = mp.getDuration() / 1000;
tvLeft.setText("00:00:00");
tvRight.setText(getTime(mp.getDuration() / 1000));
mp.setLooping(true);
RangeSeekBar access$1000 = rangeSeekBar;
Integer valueOf = Integer.valueOf(0);
access$1000.setRangeValues(valueOf, Integer.valueOf(duration));
rangeSeekBar.setSelectedMinValue(valueOf);
rangeSeekBar.setSelectedMaxValue(Integer.valueOf(duration));
rangeSeekBar.setEnabled(true);
rangeSeekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener() {
public void onRangeSeekBarValuesChanged(RangeSeekBar bar, Object minValue, Object maxValue) {
videoView.seekTo(((Integer) minValue).intValue() * 1000);
tvLeft.setText(getTime(bar.getSelectedMinValue().intValue()));
tvRight.setText(getTime(bar.getSelectedMaxValue().intValue()));
}
});
final Handler handler = new Handler();
handler.postDelayed(r = new Runnable() {
public void run() {
if (videoView.getCurrentPosition() >= rangeSeekBar.getSelectedMaxValue().intValue() * 1000) {
videoView.seekTo(rangeSeekBar.getSelectedMinValue().intValue() * 1000);
}
handler.postDelayed(r, 1000);
}
}, 1000);
}
});
}
}
/* access modifiers changed from: private */
public String getTime(int seconds) {
int hr = seconds / 3600;
int rem = seconds % 3600;
int mn = rem / 60;
int sec = rem % 60;
StringBuilder sb = new StringBuilder();
String str = "%02d";
sb.append(String.format(str, Integer.valueOf(hr)));
String str2 = ":";
sb.append(str2);
sb.append(String.format(str, Integer.valueOf(mn)));
sb.append(str2);
sb.append(String.format(str, Integer.valueOf(sec)));
return sb.toString();
}
/* access modifiers changed from: private
public void showUnsupportedExceptionDialog() {
new Builder(this).setIcon(17301543).setTitle("Not Supported").setMessage("Device Not Supported").setCancelable(false).setPositiveButton(17039370, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).create().show();
}
*/
private void execFFmpegBinary(final String[] command) {
AdsHandling.getInstance().showProgressDialog(this, "Generating Fast Motion Video..");
//progressDialog.show();
FFmpeg.executeAsync(command, new ExecuteCallback() {
@Override
public void apply(long executionId, int returnCode) {
if(returnCode==RETURN_CODE_SUCCESS){
onSuccess("");
GlobalData.EXECUTION_ID_FAST = executionId;
}else if(returnCode==RETURN_CODE_CANCEL){
onFailure("");
GlobalData.EXECUTION_ID_FAST = executionId;
}
}
public void onFailure(String s) {
String sb = "FAILED with output : " + s;
// progressDialog.dismiss();
Log.d(TAG, sb);
AdsHandling.getInstance().dismissDialog();
// FFmpeg.cancel();
}
public void onSuccess(String s) {
String sb = "SUCCESS with output : " + s;
Log.d(TAG, sb);
AdsHandling.getInstance().dismissDialog();
// FFmpeg.cancel();
Snackbar.make(mainlayout, "Generated Successfully", 4000).show();
if (choice == 5) {
Intent intent = new Intent(FastMotion.this, SaveVideoActivity.class);
// intent.putExtra("filepath", filePath);
SharedPrefs.save(application, SharedPrefs.video_path, Share.video_path = filePath);
startActivity(intent);
finish();
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
AdsHandling.getInstance().dismissDialog();
// FFmpeg.cancel();
// if (GlobalData.EXECUTION_ID == -1) {
// FFmpeg.cancel(GlobalData.EXECUTION_ID);
// }
}
// private String getPath(Context context, Uri uri) {
// if (!(VERSION.SDK_INT >= 19) || !DocumentsContract.isDocumentUri(context, uri)) {
// if (Param.CONTENT.equalsIgnoreCase(uri.getScheme())) {
// return getDataColumn(context, uri, null, null);
// }
// if ("file".equalsIgnoreCase(uri.getScheme())) {
// return uri.getPath();
// }
// } else {
// String str = ":";
// if (isExternalStorageDocument(uri)) {
// String[] split = DocumentsContract.getDocumentId(uri).split(str);
// if ("primary".equalsIgnoreCase(split[0])) {
// StringBuilder sb = new StringBuilder();
// sb.append(Environment.getExternalStorageDirectory());
// sb.append("/");
// sb.append(split[1]);
// return sb.toString();
// }
// } else if (isDownloadsDocument(uri)) {
// return getDataColumn(context, ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(DocumentsContract.getDocumentId(uri)).longValue()), null, null);
// } else if (isMediaDocument(uri)) {
// String[] split2 = DocumentsContract.getDocumentId(uri).split(str);
// String type = split2[0];
// Uri contentUri = null;
// if ("image".equals(type)) {
// contentUri = Media.EXTERNAL_CONTENT_URI;
// } else if ("video".equals(type)) {
// contentUri = Video.Media.EXTERNAL_CONTENT_URI;
// } else if ("audio".equals(type)) {
// contentUri = Audio.Media.EXTERNAL_CONTENT_URI;
// }
// String str2 = "_id=?";
// return getDataColumn(context, contentUri, "_id=?", new String[]{split2[1]});
// }
// }
// return null;
// }
/* JADX INFO: finally extract failed */
private String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
String str = "_data";
String str2 = "_data";
try {
Cursor cursor2 = context.getContentResolver().query(uri, new String[]{str2}, selection, selectionArgs, null);
if (cursor2 == null || !cursor2.moveToFirst()) {
if (cursor2 != null) {
cursor2.close();
}
return null;
}
String string = cursor2.getString(cursor2.getColumnIndexOrThrow(str2));
if (cursor2 != null) {
cursor2.close();
}
return string;
} catch (Throwable th) {
if (cursor != null) {
cursor.close();
}
throw th;
}
}
private boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
private boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
private boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
private void getAudioPermission() {
String[] params = null;
String recordAudio = "android.permission.RECORD_AUDIO";
String modifyAudio = "android.permission.MODIFY_AUDIO_SETTINGS";
int hasRecordAudioPermission = ActivityCompat.checkSelfPermission(this, recordAudio);
int hasModifyAudioPermission = ActivityCompat.checkSelfPermission(this, modifyAudio);
List<String> permissions = new ArrayList<>();
if (hasRecordAudioPermission != 0) {
permissions.add(recordAudio);
}
if (hasModifyAudioPermission != 0) {
permissions.add(modifyAudio);
}
if (!permissions.isEmpty()) {
params = permissions.toArray(new String[permissions.size()]);
}
if (params != null && params.length > 0) {
ActivityCompat.requestPermissions(this, params, Callback.DEFAULT_DRAG_ANIMATION_DURATION);
}
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 100 && grantResults.length > 0 && grantResults[0] == 0) {
uploadVideo();
}
}
// public boolean onOptionsItemSelected(MenuItem item) {
// String str = "android.intent.action.VIEW";
// switch (item.getItemId()) {
// case R.id.exit /*2131230880*/:
// finish();
// return true;
// case R.id.more_apps /*2131230953*/:
// Intent i = new Intent(str);
// i.setData(Uri.parse("https://play.google.com/store/apps/developer?id=Tim+Tim+Apps"));
// startActivity(i);
// return true;
// case R.id.privacy /*2131231007*/:
// Privacy_Policy.newInstance("www.google.com").show(getSupportFragmentManager(), "frg_pp");
// return true;
// case R.id.rate_us /*2131231012*/:
// StringBuilder sb = new StringBuilder();
// sb.append("market://details?id=");
// sb.append(getApplicationContext().getPackageName());
// startActivity(new Intent(str, Uri.parse(sb.toString())));
// return true;
// case R.id.share /*2131231046*/:
// StringBuilder sb2 = new StringBuilder();
// sb2.append("https://play.google.com/store/apps/details?id=");
// sb2.append(getPackageName());
// fun_UrlUtils_Social.ShareText(this, sb2.toString());
// return true;
// default:
// return super.onOptionsItemSelected(item);
// }
// }
//
// public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.menu_main, menu);
// return true;
// }
public void onBackPressed() {
super.onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment