-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,001 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*/build/ | ||
build/ | ||
buildCacheDir/ | ||
|
||
# Crashlytics configuations | ||
com_crashlytics_export_strings.xml | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Gradle generated files | ||
.gradle/ | ||
|
||
# built application files | ||
# *.apk | ||
# *.ap_ | ||
|
||
# Signing files | ||
.signing/ | ||
|
||
# files for the dex VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# generated files | ||
bin/ | ||
gen/ | ||
obj/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
# Eclipse project files | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Intellij project files | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
.idea/ | ||
Thumbs.db | ||
.DS_Store | ||
.checkstyle | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
ehthumbs.db | ||
|
||
fabric.properties | ||
|
||
.externalNativeBuild |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
defaultConfig { | ||
applicationId "com.superman.fastffmpegandroid" | ||
minSdkVersion 15 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
jniLibs.srcDirs = ['libs'] | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
|
||
implementation 'com.github.tbruyelle:rxpermissions:0.10.2' | ||
|
||
} |
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/superman/fastffmpegandroid/ExampleInstrumentedTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.superman.fastffmpegandroid; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.superman.fastffmpegandroid", appContext.getPackageName()); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.superman.fastffmpegandroid"> | ||
|
||
<!--网络连接--> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<!--sd卡读写 6.0以上系统可能还需要动态申请sd卡读写权限--> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
158 changes: 158 additions & 0 deletions
158
app/src/main/java/com/superman/fastffmpegandroid/MainActivity.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package com.superman.fastffmpegandroid; | ||
|
||
import android.Manifest; | ||
import android.app.ProgressDialog; | ||
import android.content.DialogInterface; | ||
import android.os.Environment; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.superman.ffmpeg.FFmpegInvoke; | ||
import com.tbruyelle.rxpermissions2.RxPermissions; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import io.reactivex.functions.Consumer; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = MainActivity.class.getSimpleName(); | ||
|
||
private ExecutorService es = Executors.newSingleThreadExecutor(); | ||
String path = Environment.getExternalStorageDirectory().getPath(); | ||
|
||
//需要申请的权限,必须先在AndroidManifest.xml有声明,才可以动态获取权限 | ||
private static String[] PERMISSIONS_STORAGE = { | ||
Manifest.permission.READ_EXTERNAL_STORAGE, | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE}; | ||
|
||
private TextView tv; | ||
|
||
private EditText editText; | ||
|
||
private ProgressDialog mProgressDialog; | ||
|
||
//权限 | ||
private RxPermissions rxPermissions = null; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
rxPermissions = new RxPermissions(this); | ||
|
||
tv = (TextView)findViewById(R.id.sample_text); | ||
// tv.setText(path); | ||
|
||
editText = (EditText)findViewById(R.id.editText); | ||
editText.setText("ffmpeg -y -i /storage/emulated/0/1/qq.mp4 -vf boxblur=5:1 -preset superfast /storage/emulated/0/1/result.mp4"); | ||
|
||
FFmpegInvoke.getInstance().setDebug(true); | ||
|
||
tv.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
rxPermissions.request(PERMISSIONS_STORAGE).subscribe(new Consumer<Boolean>() { | ||
@Override | ||
public void accept(Boolean aBoolean) throws Exception { | ||
if (aBoolean) {// 用户同意了权限 | ||
runFFmpeg (); | ||
|
||
} else {//用户拒绝了权限 | ||
Toast.makeText(MainActivity.this,"您拒绝了权限,请往设置里开启权限",Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
}); | ||
|
||
} | ||
|
||
private void runFFmpeg () { | ||
openProgressDialog(); | ||
final String text = editText.getText().toString(); | ||
String[] commands = text.split(" "); | ||
|
||
FFmpegInvoke.getInstance().runCommand(commands, new FFmpegInvoke.IFFmpegListener() { | ||
@Override | ||
public void onFinish() { | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (mProgressDialog != null) | ||
mProgressDialog.cancel(); | ||
tv.setText("处理成功"); | ||
Toast.makeText(MainActivity.this, "处理成功", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onProgress(final int progress) { | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (mProgressDialog != null) | ||
mProgressDialog.setProgress(progress); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onCancel() { | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (mProgressDialog != null) | ||
mProgressDialog.cancel(); | ||
tv.setText("onCancel"); | ||
Toast.makeText(MainActivity.this, "已取消", Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onError(final String message) { | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (mProgressDialog != null) | ||
mProgressDialog.cancel(); | ||
tv.setText("onError=" + message); | ||
Toast.makeText(MainActivity.this, "onError=" + message, Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
public void openProgressDialog() { | ||
mProgressDialog = new ProgressDialog(this); | ||
final int totalProgressTime = 100; | ||
mProgressDialog.setMessage("正在转换视频,请勿取消"); | ||
mProgressDialog.setButton("取消", new DialogInterface.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// TODO Auto-generated method stub | ||
FFmpegInvoke.getInstance().exit(); | ||
|
||
} | ||
}); | ||
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); | ||
mProgressDialog.setCancelable(false); | ||
mProgressDialog.setMax(totalProgressTime); | ||
mProgressDialog.show(); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.