mirror of
https://github.com/androidx/media.git
synced 2025-05-08 08:00:49 +08:00
Fix "Transforming media" page
Some information there is not correct anymore. PiperOrigin-RevId: 503141754
This commit is contained in:
parent
4f6b83e2c3
commit
ad51d1ca87
@ -37,16 +37,14 @@ Transformer transformer =
|
|||||||
.addListener(transformerListener)
|
.addListener(transformerListener)
|
||||||
.build();
|
.build();
|
||||||
// Start the transformation.
|
// Start the transformation.
|
||||||
transformer.startTransformation(inputMediaItem, outputPath);
|
transformer.startTransformation(
|
||||||
|
new EditedMediaItem(inputMediaItem), outputPath);
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
||||||
Other parameters, such as the `MediaSource.Factory`, can be passed to the
|
`startTransformation` receives an `EditedMediaItem` describing the input, and a
|
||||||
builder.
|
path or a `ParcelFileDescriptor` indicating where the output should be written.
|
||||||
|
The input can be a progressive or an adaptive stream, but the output is always a
|
||||||
`startTransformation` receives a `MediaItem` describing the input, and a path or
|
|
||||||
a `ParcelFileDescriptor` indicating where the output should be written. The
|
|
||||||
input can be a progressive or an adaptive stream, but the output is always a
|
|
||||||
progressive stream. For adaptive inputs, the highest resolution tracks are
|
progressive stream. For adaptive inputs, the highest resolution tracks are
|
||||||
always selected for the transformation. The input can be of any container format
|
always selected for the transformation. The input can be of any container format
|
||||||
supported by ExoPlayer (see the [Supported formats page][] for details), but the
|
supported by ExoPlayer (see the [Supported formats page][] for details), but the
|
||||||
@ -65,12 +63,16 @@ app is notified of events via the listener passed to the `Transformer` builder.
|
|||||||
Transformer.Listener transformerListener =
|
Transformer.Listener transformerListener =
|
||||||
new Transformer.Listener() {
|
new Transformer.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTransformationCompleted(MediaItem inputMediaItem, TransformationResult result) {
|
public void onTransformationCompleted(
|
||||||
|
MediaItem inputMediaItem, TransformationResult result) {
|
||||||
playOutput();
|
playOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTransformationError(MediaItem inputMediaItem, TransformationResult result, TransformationException exception) {
|
public void onTransformationError(
|
||||||
|
MediaItem inputMediaItem,
|
||||||
|
TransformationResult result,
|
||||||
|
TransformationException exception) {
|
||||||
displayError(e);
|
displayError(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -88,13 +90,15 @@ the `updateProgressInUi` method could be implemented to update a progress bar
|
|||||||
displayed to the user.
|
displayed to the user.
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
transformer.startTransformation(inputMediaItem, outputPath);
|
transformer.startTransformation(
|
||||||
|
new EditedMediaItem(inputMediaItem), outputPath);
|
||||||
ProgressHolder progressHolder = new ProgressHolder();
|
ProgressHolder progressHolder = new ProgressHolder();
|
||||||
mainHandler.post(
|
mainHandler.post(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ProgressState int progressState = transformer.getProgress(progressHolder);
|
@ProgressState int progressState =
|
||||||
|
transformer.getProgress(progressHolder);
|
||||||
updateProgressInUi(progressState, progressHolder);
|
updateProgressInUi(progressState, progressHolder);
|
||||||
if (progressState != PROGRESS_STATE_NOT_STARTED) {
|
if (progressState != PROGRESS_STATE_NOT_STARTED) {
|
||||||
mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500);
|
mainHandler.postDelayed(/* r= */ this, /* delayMillis= */ 500);
|
||||||
@ -123,7 +127,8 @@ Transformer transformer =
|
|||||||
.setFlattenForSlowMotion(true)
|
.setFlattenForSlowMotion(true)
|
||||||
.addListener(transformerListener)
|
.addListener(transformerListener)
|
||||||
.build();
|
.build();
|
||||||
transformer.startTransformation(inputMediaItem, outputPath);
|
transformer.startTransformation(
|
||||||
|
new EditedMediaItem(inputMediaItem), outputPath);
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user