Fix input video duration in the result view in transformer demo
PiperOrigin-RevId: 524305085
This commit is contained in:
parent
9835e58e4c
commit
fab3abfd7c
@ -222,7 +222,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
requestReadVideoPermission(/* activity= */ this);
|
requestReadVideoPermission(/* activity= */ this);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
Uri uri = checkNotNull(intent.getData());
|
Uri inputUri = checkNotNull(intent.getData());
|
||||||
try {
|
try {
|
||||||
externalCacheFile = createExternalCacheFile("transformer-output.mp4");
|
externalCacheFile = createExternalCacheFile("transformer-output.mp4");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -230,9 +230,9 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
String filePath = externalCacheFile.getAbsolutePath();
|
String filePath = externalCacheFile.getAbsolutePath();
|
||||||
@Nullable Bundle bundle = intent.getExtras();
|
@Nullable Bundle bundle = intent.getExtras();
|
||||||
MediaItem mediaItem = createMediaItem(bundle, uri);
|
MediaItem mediaItem = createMediaItem(bundle, inputUri);
|
||||||
try {
|
try {
|
||||||
Transformer transformer = createTransformer(bundle, filePath);
|
Transformer transformer = createTransformer(bundle, inputUri, filePath);
|
||||||
Composition composition = createComposition(mediaItem, bundle);
|
Composition composition = createComposition(mediaItem, bundle);
|
||||||
exportStopwatch.start();
|
exportStopwatch.start();
|
||||||
transformer.start(composition, filePath);
|
transformer.start(composition, filePath);
|
||||||
@ -296,7 +296,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
"progressViewGroup",
|
"progressViewGroup",
|
||||||
"debugFrame",
|
"debugFrame",
|
||||||
})
|
})
|
||||||
private Transformer createTransformer(@Nullable Bundle bundle, String filePath) {
|
private Transformer createTransformer(@Nullable Bundle bundle, Uri inputUri, String filePath) {
|
||||||
Transformer.Builder transformerBuilder = new Transformer.Builder(/* context= */ this);
|
Transformer.Builder transformerBuilder = new Transformer.Builder(/* context= */ this);
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
TransformationRequest.Builder requestBuilder = new TransformationRequest.Builder();
|
TransformationRequest.Builder requestBuilder = new TransformationRequest.Builder();
|
||||||
@ -331,9 +331,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
new Transformer.Listener() {
|
new Transformer.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted(Composition composition, ExportResult exportResult) {
|
public void onCompleted(Composition composition, ExportResult exportResult) {
|
||||||
MediaItem mediaItem =
|
TransformerActivity.this.onCompleted(inputUri, filePath);
|
||||||
composition.sequences.get(0).editedMediaItems.get(0).mediaItem;
|
|
||||||
TransformerActivity.this.onCompleted(filePath, mediaItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -658,7 +656,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
"debugFrame",
|
"debugFrame",
|
||||||
"exportStopwatch",
|
"exportStopwatch",
|
||||||
})
|
})
|
||||||
private void onCompleted(String filePath, MediaItem inputMediaItem) {
|
private void onCompleted(Uri inputUri, String filePath) {
|
||||||
exportStopwatch.stop();
|
exportStopwatch.stop();
|
||||||
informationTextView.setText(
|
informationTextView.setText(
|
||||||
getString(R.string.export_completed, exportStopwatch.elapsed(TimeUnit.SECONDS)));
|
getString(R.string.export_completed, exportStopwatch.elapsed(TimeUnit.SECONDS)));
|
||||||
@ -669,7 +667,7 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
outputVideoTextView.setVisibility(View.VISIBLE);
|
outputVideoTextView.setVisibility(View.VISIBLE);
|
||||||
debugTextView.setVisibility(View.VISIBLE);
|
debugTextView.setVisibility(View.VISIBLE);
|
||||||
displayInputButton.setVisibility(View.VISIBLE);
|
displayInputButton.setVisibility(View.VISIBLE);
|
||||||
playMediaItems(inputMediaItem, MediaItem.fromUri("file://" + filePath));
|
playMediaItems(MediaItem.fromUri(inputUri), MediaItem.fromUri("file://" + filePath));
|
||||||
Log.d(TAG, "Output file path: file://" + filePath);
|
Log.d(TAG, "Output file path: file://" + filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,8 +683,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
inputPlayerView.setPlayer(null);
|
inputPlayerView.setPlayer(null);
|
||||||
outputPlayerView.setPlayer(null);
|
outputPlayerView.setPlayer(null);
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
Uri uri = checkNotNull(inputMediaItem.localConfiguration).uri;
|
|
||||||
|
|
||||||
|
Uri uri = checkNotNull(inputMediaItem.localConfiguration).uri;
|
||||||
ExoPlayer outputPlayer = new ExoPlayer.Builder(/* context= */ this).build();
|
ExoPlayer outputPlayer = new ExoPlayer.Builder(/* context= */ this).build();
|
||||||
outputPlayerView.setPlayer(outputPlayer);
|
outputPlayerView.setPlayer(outputPlayer);
|
||||||
outputPlayerView.setControllerAutoShow(false);
|
outputPlayerView.setControllerAutoShow(false);
|
||||||
@ -717,8 +715,8 @@ public final class TransformerActivity extends AppCompatActivity {
|
|||||||
ExoPlayer inputPlayer = new ExoPlayer.Builder(/* context= */ this).build();
|
ExoPlayer inputPlayer = new ExoPlayer.Builder(/* context= */ this).build();
|
||||||
inputPlayerView.setPlayer(inputPlayer);
|
inputPlayerView.setPlayer(inputPlayer);
|
||||||
inputPlayerView.setControllerAutoShow(false);
|
inputPlayerView.setControllerAutoShow(false);
|
||||||
inputPlayer.setMediaItem(inputMediaItem);
|
|
||||||
inputPlayerView.setOnClickListener(this::onClickingPlayerView);
|
inputPlayerView.setOnClickListener(this::onClickingPlayerView);
|
||||||
|
inputPlayer.setMediaItem(inputMediaItem);
|
||||||
inputPlayer.prepare();
|
inputPlayer.prepare();
|
||||||
this.inputPlayer = inputPlayer;
|
this.inputPlayer = inputPlayer;
|
||||||
inputPlayer.setVolume(0f);
|
inputPlayer.setVolume(0f);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user