mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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 TextView informationTextView;
|
||||||
private @MonotonicNonNull ViewGroup progressViewGroup;
|
private @MonotonicNonNull ViewGroup progressViewGroup;
|
||||||
private @MonotonicNonNull LinearProgressIndicator progressIndicator;
|
private @MonotonicNonNull LinearProgressIndicator progressIndicator;
|
||||||
|
private @MonotonicNonNull Button cancelButton;
|
||||||
|
private @MonotonicNonNull Button resumeButton;
|
||||||
private @MonotonicNonNull Stopwatch exportStopwatch;
|
private @MonotonicNonNull Stopwatch exportStopwatch;
|
||||||
private @MonotonicNonNull AspectRatioFrameLayout debugFrame;
|
private @MonotonicNonNull AspectRatioFrameLayout debugFrame;
|
||||||
|
|
||||||
@ -147,6 +149,10 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
informationTextView = findViewById(R.id.information_text_view);
|
informationTextView = findViewById(R.id.information_text_view);
|
||||||
progressViewGroup = findViewById(R.id.progress_view_group);
|
progressViewGroup = findViewById(R.id.progress_view_group);
|
||||||
progressIndicator = findViewById(R.id.progress_indicator);
|
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);
|
debugFrame = findViewById(R.id.debug_aspect_ratio_frame_layout);
|
||||||
displayInputButton = findViewById(R.id.display_input_button);
|
displayInputButton = findViewById(R.id.display_input_button);
|
||||||
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay);
|
displayInputButton.setOnClickListener(this::toggleInputVideoDisplay);
|
||||||
@ -165,31 +171,20 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.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();
|
startExport();
|
||||||
|
|
||||||
inputPlayerView.onResume();
|
checkNotNull(inputPlayerView).onResume();
|
||||||
outputPlayerView.onResume();
|
checkNotNull(outputPlayerView).onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
checkNotNull(transformer).cancel();
|
if (transformer != null) {
|
||||||
transformer = null;
|
transformer.cancel();
|
||||||
|
transformer = null;
|
||||||
|
}
|
||||||
|
|
||||||
// The stop watch is reset after cancelling the export, in case cancelling causes the stop watch
|
// The stop watch is reset after cancelling the export, in case cancelling causes the stop watch
|
||||||
// to be stopped in a transformer callback.
|
// to be stopped in a transformer callback.
|
||||||
@ -203,22 +198,23 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
externalCacheFile = null;
|
externalCacheFile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresNonNull({
|
|
||||||
"displayInputButton",
|
|
||||||
"inputCardView",
|
|
||||||
"inputTextView",
|
|
||||||
"inputImageView",
|
|
||||||
"inputPlayerView",
|
|
||||||
"outputPlayerView",
|
|
||||||
"outputVideoTextView",
|
|
||||||
"debugTextView",
|
|
||||||
"informationTextView",
|
|
||||||
"progressIndicator",
|
|
||||||
"exportStopwatch",
|
|
||||||
"progressViewGroup",
|
|
||||||
"debugFrame",
|
|
||||||
})
|
|
||||||
private void startExport() {
|
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);
|
requestReadVideoPermission(/* activity= */ this);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
@ -243,6 +239,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
debugTextView.setVisibility(View.GONE);
|
debugTextView.setVisibility(View.GONE);
|
||||||
informationTextView.setText(R.string.export_started);
|
informationTextView.setText(R.string.export_started);
|
||||||
progressViewGroup.setVisibility(View.VISIBLE);
|
progressViewGroup.setVisibility(View.VISIBLE);
|
||||||
|
cancelButton.setVisibility(View.VISIBLE);
|
||||||
|
resumeButton.setVisibility(View.GONE);
|
||||||
Handler mainHandler = new Handler(getMainLooper());
|
Handler mainHandler = new Handler(getMainLooper());
|
||||||
ProgressHolder progressHolder = new ProgressHolder();
|
ProgressHolder progressHolder = new ProgressHolder();
|
||||||
mainHandler.post(
|
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 final class DemoDebugViewProvider implements DebugViewProvider {
|
||||||
|
|
||||||
private @MonotonicNonNull SurfaceView surfaceView;
|
private @MonotonicNonNull SurfaceView surfaceView;
|
||||||
|
@ -159,6 +159,18 @@
|
|||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:text="@string/debug_preview" />
|
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
|
<androidx.media3.ui.AspectRatioFrameLayout
|
||||||
android:id="@+id/debug_aspect_ratio_frame_layout"
|
android:id="@+id/debug_aspect_ratio_frame_layout"
|
||||||
android:layout_width="match_parent"
|
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="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="export" translatable="false">Export</string>
|
||||||
<string name="debug_preview" translatable="false">Debug preview:</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="debug_preview_not_available" translatable="false">No debug preview available.</string>
|
||||||
<string name="export_started" translatable="false">Export started</string>
|
<string name="export_started" translatable="false">Export started</string>
|
||||||
<string name="export_timer" translatable="false">Export started %d seconds ago.</string>
|
<string name="export_timer" translatable="false">Export started %d seconds ago.</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user