Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply keep screen awake & fix ffmpeg session termination #4

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/src/main/java/com/eikarna/smoothvideoapp/FilterWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class FilterWorker extends Worker {
private static final String TAG = "FilterWorker";
private FFmpegSession session;

public FilterWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
Expand Down Expand Up @@ -84,7 +85,7 @@ public Result doWork() {
});

// Execute the FFmpeg command
FFmpegSession session = FFmpegKit.execute(ffmpegCommand.toString());
session = FFmpegKit.execute(ffmpegCommand.toString());
Log.d(TAG, "FFmpeg output: " + session.getOutput());
Log.e(TAG, "FFmpeg error: " + session.getFailStackTrace());

Expand All @@ -97,6 +98,14 @@ public Result doWork() {
return Result.failure();
}
}

@Override
public void onStopped() {
super.onStopped();
if (session != null) {
session.cancel(); // Stop FFmpeg session gracefully
}
}

// Function to format the log message
private String formatLogMessage(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -237,12 +238,14 @@ private void acquireWakeLock() {
powerManager.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "SmoothVideoApp::VideoProcessingLock");
wakeLock.acquire();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

private void releaseWakeLock() {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

private void selectVideo() {
Expand Down