Created
August 17, 2017 18:35
-
-
Save zoecarver/cbe4c7096c8ae1df334b419c8ea22151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.reactlibrary; | |
| import android.content.Intent; | |
| import android.net.Uri; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.util.Log; | |
| import com.facebook.react.bridge.ReactApplicationContext; | |
| import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; | |
| import com.github.hiteshsondhi88.libffmpeg.FFmpeg; | |
| import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException; | |
| public class MainActivity extends AppCompatActivity { | |
| private ExecuteBinaryResponseHandler responseHandler = new ExecuteBinaryResponseHandler() { | |
| @Override | |
| public void onSuccess(String message) { | |
| super.onSuccess(message); | |
| Log.d(App.LOG, message); | |
| openGif(); | |
| } | |
| @Override | |
| public void onProgress(String message) { | |
| super.onProgress(message); | |
| Log.d(App.LOG, message); | |
| } | |
| @Override | |
| public void onFailure(String message) { | |
| super.onFailure(message); | |
| Log.d(App.LOG, message); | |
| } | |
| @Override | |
| public void onStart() { | |
| super.onStart(); | |
| } | |
| @Override | |
| public void onFinish() { | |
| super.onFinish(); | |
| } | |
| }; | |
| public void convert() { | |
| FFmpeg ffmpeg = FFmpeg.getInstance(this); | |
| try { | |
| String command = "-y " | |
| + "-i " | |
| + App.VIDEO_FILE.getAbsolutePath() | |
| + " " | |
| + App.GIF_FILE.getAbsolutePath(); | |
| ffmpeg.execute(command.split(" "), responseHandler); | |
| } catch (FFmpegCommandAlreadyRunningException e) { | |
| Log.e(App.LOG, e.getMessage()); | |
| } | |
| } | |
| private void openGif(){ | |
| Intent intent = new Intent(); | |
| intent.setAction(Intent.ACTION_VIEW); | |
| intent.setDataAndType(Uri.fromFile(App.GIF_FILE), "image/*"); | |
| startActivity(intent); | |
| } | |
| private final ReactApplicationContext reactContext; | |
| public MainActivity(ReactApplicationContext reactContext) { | |
| super(reactContext); | |
| this.reactContext = reactContext; | |
| convert(); | |
| } | |
| @Override | |
| public String getName() { | |
| return "RNGifMaker"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment