-
Notifications
You must be signed in to change notification settings - Fork 826
Expand file tree
/
Copy pathFFmpegLoadLibraryAsyncTask.java
More file actions
63 lines (54 loc) · 2.33 KB
/
FFmpegLoadLibraryAsyncTask.java
File metadata and controls
63 lines (54 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.github.hiteshsondhi88.libffmpeg;
import android.content.Context;
import android.os.AsyncTask;
import java.io.File;
class FFmpegLoadLibraryAsyncTask extends AsyncTask<Void, Void, Boolean> {
private final String cpuArchNameFromAssets;
private final FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler;
private final FFmpegContextProvider context;
FFmpegLoadLibraryAsyncTask(FFmpegContextProvider context, String cpuArchNameFromAssets, FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler) {
this.context = context;
this.cpuArchNameFromAssets = cpuArchNameFromAssets;
this.ffmpegLoadBinaryResponseHandler = ffmpegLoadBinaryResponseHandler;
}
@Override
protected Boolean doInBackground(Void... params) {
File ffmpegFile = new File(FileUtils.getFFmpeg(context.provide()));
if (ffmpegFile.exists() && isDeviceFFmpegVersionOld() && !ffmpegFile.delete()) {
return false;
}
if (!ffmpegFile.exists()) {
boolean isFileCopied = FileUtils.copyBinaryFromAssetsToData(context.provide(),
cpuArchNameFromAssets + File.separator + FileUtils.ffmpegFileName,
FileUtils.ffmpegFileName);
// make file executable
if (isFileCopied) {
if(!ffmpegFile.canExecute()) {
Log.d("FFmpeg is not executable, trying to make it executable ...");
if (ffmpegFile.setExecutable(true)) {
return true;
}
} else {
Log.d("FFmpeg is executable");
return true;
}
}
}
return ffmpegFile.exists() && ffmpegFile.canExecute();
}
@Override
protected void onPostExecute(Boolean isSuccess) {
super.onPostExecute(isSuccess);
if (ffmpegLoadBinaryResponseHandler != null) {
if (isSuccess) {
ffmpegLoadBinaryResponseHandler.onSuccess();
} else {
ffmpegLoadBinaryResponseHandler.onFailure();
}
ffmpegLoadBinaryResponseHandler.onFinish();
}
}
private boolean isDeviceFFmpegVersionOld() {
return CpuArch.fromString(FileUtils.SHA1(FileUtils.getFFmpeg(context.provide()))).equals(CpuArch.NONE);
}
}