Class Transformer
- java.lang.Object
-
- com.google.android.exoplayer2.transformer.Transformer
-
public final class Transformer extends Object
A transformer to transform media inputs.The same Transformer instance can be used to transform multiple inputs (sequentially, not concurrently).
Transformer instances must be accessed from a single application thread. For the vast majority of cases this should be the application's main thread. The thread on which a Transformer instance must be accessed can be explicitly specified by passing a
Looper
when creating the transformer. If no Looper is specified, then the Looper of the thread that theTransformer.Builder
is created on is used, or if that thread does not have a Looper, the Looper of the application's main thread is used. In all cases the Looper of the thread from which the transformer must be accessed can be queried usinggetApplicationLooper()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Transformer.Builder
A builder forTransformer
instances.static interface
Transformer.Listener
A listener for the transformation events.static interface
Transformer.ProgressState
Progress state.
-
Field Summary
Fields Modifier and Type Field Description static int
PROGRESS_STATE_AVAILABLE
Indicates that the progress is available.static int
PROGRESS_STATE_NO_TRANSFORMATION
Indicates that there is no current transformation.static int
PROGRESS_STATE_UNAVAILABLE
Indicates that the progress is permanently unavailable for the current transformation.static int
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
Indicates that the progress is unavailable for the current transformation, but might become available.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addListener(Transformer.Listener listener)
Adds aTransformer.Listener
to listen to the transformation events.Transformer.Builder
buildUpon()
Returns aTransformer.Builder
initialized with the values of this instance.void
cancel()
Cancels the transformation that is currently in progress, if any.Looper
getApplicationLooper()
Returns theLooper
associated with the application thread that's used to access the transformer and on which transformer events are received.@com.google.android.exoplayer2.transformer.Transformer.ProgressState int
getProgress(ProgressHolder progressHolder)
Returns the currentTransformer.ProgressState
and updatesprogressHolder
with the current progress if it isavailable
.void
removeAllListeners()
Removes all listeners.void
removeListener(Transformer.Listener listener)
Removes aTransformer.Listener
.void
setListener(Transformer.Listener listener)
Deprecated.void
startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
Starts an asynchronous operation to transform the givenMediaItem
.void
startTransformation(MediaItem mediaItem, String path)
Starts an asynchronous operation to transform the givenMediaItem
.
-
-
-
Field Detail
-
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
public static final int PROGRESS_STATE_WAITING_FOR_AVAILABILITY
Indicates that the progress is unavailable for the current transformation, but might become available.- See Also:
- Constant Field Values
-
PROGRESS_STATE_AVAILABLE
public static final int PROGRESS_STATE_AVAILABLE
Indicates that the progress is available.- See Also:
- Constant Field Values
-
PROGRESS_STATE_UNAVAILABLE
public static final int PROGRESS_STATE_UNAVAILABLE
Indicates that the progress is permanently unavailable for the current transformation.- See Also:
- Constant Field Values
-
PROGRESS_STATE_NO_TRANSFORMATION
public static final int PROGRESS_STATE_NO_TRANSFORMATION
Indicates that there is no current transformation.- See Also:
- Constant Field Values
-
-
Method Detail
-
buildUpon
public Transformer.Builder buildUpon()
Returns aTransformer.Builder
initialized with the values of this instance.
-
setListener
@Deprecated public void setListener(Transformer.Listener listener)
Deprecated.
-
addListener
public void addListener(Transformer.Listener listener)
Adds aTransformer.Listener
to listen to the transformation events.- Parameters:
listener
- ATransformer.Listener
.- Throws:
IllegalStateException
- If this method is called from the wrong thread.
-
removeListener
public void removeListener(Transformer.Listener listener)
Removes aTransformer.Listener
.- Parameters:
listener
- ATransformer.Listener
.- Throws:
IllegalStateException
- If this method is called from the wrong thread.
-
removeAllListeners
public void removeAllListeners()
Removes all listeners.- Throws:
IllegalStateException
- If this method is called from the wrong thread.
-
startTransformation
public void startTransformation(MediaItem mediaItem, String path)
Starts an asynchronous operation to transform the givenMediaItem
.The transformation state is notified through the listener.
Concurrent transformations on the same Transformer object are not allowed.
The output is an MP4 file. It can contain at most one video track and one audio track. Other track types are ignored. For adaptive bitrate media sources, the highest bitrate video and audio streams are selected.
- Parameters:
mediaItem
- TheMediaItem
to transform.path
- The path to the output file.- Throws:
IllegalArgumentException
- If the path is invalid.IllegalArgumentException
- If theMediaItem
is not supported.IllegalStateException
- If this method is called from the wrong thread.IllegalStateException
- If a transformation is already in progress.
-
startTransformation
@RequiresApi(26) public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)
Starts an asynchronous operation to transform the givenMediaItem
.The transformation state is notified through the listener.
Concurrent transformations on the same Transformer object are not allowed.
The output is an MP4 file. It can contain at most one video track and one audio track. Other track types are ignored. For adaptive bitrate media sources, the highest bitrate video and audio streams are selected.
- Parameters:
mediaItem
- TheMediaItem
to transform.parcelFileDescriptor
- A readable and writableParcelFileDescriptor
of the output. The file referenced by this ParcelFileDescriptor should not be used before the transformation is completed. It is the responsibility of the caller to close the ParcelFileDescriptor. This can be done after this method returns.- Throws:
IllegalArgumentException
- If the file descriptor is invalid.IllegalArgumentException
- If theMediaItem
is not supported.IllegalStateException
- If this method is called from the wrong thread.IllegalStateException
- If a transformation is already in progress.
-
getApplicationLooper
public Looper getApplicationLooper()
Returns theLooper
associated with the application thread that's used to access the transformer and on which transformer events are received.
-
getProgress
public @com.google.android.exoplayer2.transformer.Transformer.ProgressState int getProgress(ProgressHolder progressHolder)
Returns the currentTransformer.ProgressState
and updatesprogressHolder
with the current progress if it isavailable
.After a transformation completes, this method returns
PROGRESS_STATE_NO_TRANSFORMATION
.- Parameters:
progressHolder
- AProgressHolder
, updated to hold the percentage progress ifavailable
.- Returns:
- The
Transformer.ProgressState
. - Throws:
IllegalStateException
- If this method is called from the wrong thread.
-
cancel
public void cancel()
Cancels the transformation that is currently in progress, if any.- Throws:
IllegalStateException
- If this method is called from the wrong thread.
-
-