Add pause and resume button in demo app
Currently the resume button will restart the export from the beginning. PiperOrigin-RevId: 559787856
This commit is contained in:
parent
28fd43617e
commit
d5f8487fe2
@ -123,6 +123,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
private @MonotonicNonNull TextView informationTextView;
|
||||
private @MonotonicNonNull ViewGroup progressViewGroup;
|
||||
private @MonotonicNonNull LinearProgressIndicator progressIndicator;
|
||||
private @MonotonicNonNull Button cancelButton;
|
||||
private @MonotonicNonNull Button resumeButton;
|
||||
private @MonotonicNonNull Stopwatch exportStopwatch;
|
||||
private @MonotonicNonNull AspectRatioFrameLayout debugFrame;
|
||||
|
||||
@ -147,6 +149,10 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
informationTextView = findViewById(R.id.information_text_view);
|
||||
progressViewGroup = findViewById(R.id.progress_view_group);
|
||||
progressIndicator = findViewById(R.id.progress_indicator);
|
||||
cancelButton = findViewById(R.id.cancel_button);
|
||||
cancelButton.setOnClickListener(this::cancelExport);
|
||||
resumeButton = findViewById(R.id.resume_button);
|
||||
resumeButton.setOnClickListener(this::resumeExport);
|
||||
debugFrame = findViewById(R.id.debug_aspect_ratio_frame_layout);
|
||||
displayInputButton = findViewById(R.id.display_input_button);
|
||||
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay);
|
||||
@ -165,31 +171,20 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
checkNotNull(progressIndicator);
|
||||
checkNotNull(informationTextView);
|
||||
checkNotNull(exportStopwatch);
|
||||
checkNotNull(inputCardView);
|
||||
checkNotNull(inputTextView);
|
||||
checkNotNull(inputImageView);
|
||||
checkNotNull(inputPlayerView);
|
||||
checkNotNull(outputPlayerView);
|
||||
checkNotNull(outputVideoTextView);
|
||||
checkNotNull(debugTextView);
|
||||
checkNotNull(progressViewGroup);
|
||||
checkNotNull(debugFrame);
|
||||
checkNotNull(displayInputButton);
|
||||
startExport();
|
||||
|
||||
inputPlayerView.onResume();
|
||||
outputPlayerView.onResume();
|
||||
checkNotNull(inputPlayerView).onResume();
|
||||
checkNotNull(outputPlayerView).onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
checkNotNull(transformer).cancel();
|
||||
transformer = null;
|
||||
if (transformer != null) {
|
||||
transformer.cancel();
|
||||
transformer = null;
|
||||
}
|
||||
|
||||
// The stop watch is reset after cancelling the export, in case cancelling causes the stop watch
|
||||
// to be stopped in a transformer callback.
|
||||
@ -203,22 +198,23 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
externalCacheFile = null;
|
||||
}
|
||||
|
||||
@RequiresNonNull({
|
||||
"displayInputButton",
|
||||
"inputCardView",
|
||||
"inputTextView",
|
||||
"inputImageView",
|
||||
"inputPlayerView",
|
||||
"outputPlayerView",
|
||||
"outputVideoTextView",
|
||||
"debugTextView",
|
||||
"informationTextView",
|
||||
"progressIndicator",
|
||||
"exportStopwatch",
|
||||
"progressViewGroup",
|
||||
"debugFrame",
|
||||
})
|
||||
private void startExport() {
|
||||
checkNotNull(progressIndicator);
|
||||
checkNotNull(informationTextView);
|
||||
checkNotNull(exportStopwatch);
|
||||
checkNotNull(inputCardView);
|
||||
checkNotNull(inputTextView);
|
||||
checkNotNull(inputImageView);
|
||||
checkNotNull(inputPlayerView);
|
||||
checkNotNull(outputPlayerView);
|
||||
checkNotNull(outputVideoTextView);
|
||||
checkNotNull(debugTextView);
|
||||
checkNotNull(progressViewGroup);
|
||||
checkNotNull(debugFrame);
|
||||
checkNotNull(displayInputButton);
|
||||
checkNotNull(cancelButton);
|
||||
checkNotNull(resumeButton);
|
||||
|
||||
requestReadVideoPermission(/* activity= */ this);
|
||||
|
||||
Intent intent = getIntent();
|
||||
@ -243,6 +239,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
debugTextView.setVisibility(View.GONE);
|
||||
informationTextView.setText(R.string.export_started);
|
||||
progressViewGroup.setVisibility(View.VISIBLE);
|
||||
cancelButton.setVisibility(View.VISIBLE);
|
||||
resumeButton.setVisibility(View.GONE);
|
||||
Handler mainHandler = new Handler(getMainLooper());
|
||||
ProgressHolder progressHolder = new ProgressHolder();
|
||||
mainHandler.post(
|
||||
@ -827,6 +825,21 @@ public final class TransformerActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresNonNull({"transformer", "exportStopwatch", "cancelButton", "resumeButton"})
|
||||
private void cancelExport(View view) {
|
||||
transformer.cancel();
|
||||
transformer = null;
|
||||
exportStopwatch.stop();
|
||||
cancelButton.setVisibility(View.GONE);
|
||||
resumeButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@RequiresNonNull({"exportStopwatch"})
|
||||
private void resumeExport(View view) {
|
||||
exportStopwatch.reset();
|
||||
startExport();
|
||||
}
|
||||
|
||||
private final class DemoDebugViewProvider implements DebugViewProvider {
|
||||
|
||||
private @MonotonicNonNull SurfaceView surfaceView;
|
||||
|
@ -159,6 +159,18 @@
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/debug_preview" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/cancel"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/resume_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/resume"/>
|
||||
|
||||
<androidx.media3.ui.AspectRatioFrameLayout
|
||||
android:id="@+id/debug_aspect_ratio_frame_layout"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -39,6 +39,8 @@
|
||||
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipeShaderProgram. Check the README for instructions.</string>
|
||||
<string name="export" translatable="false">Export</string>
|
||||
<string name="debug_preview" translatable="false">Debug preview:</string>
|
||||
<string name="cancel" translatable="false">Cancel</string>
|
||||
<string name="resume" translatable="false">Resume</string>
|
||||
<string name="debug_preview_not_available" translatable="false">No debug preview available.</string>
|
||||
<string name="export_started" translatable="false">Export started</string>
|
||||
<string name="export_timer" translatable="false">Export started %d seconds ago.</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user