public interface AsyncMedia

ExtendsMedia

Known subtypesAbstractMedia

An interface for media elements that provides asynchronous pause and play functionality as well as support for state change events, so that interested parties can register to be notified when state changes between play and pause.

You can convert any Media object into an AsyncMedia object using MediaManager#getAsyncMedia(com.codename1.media.Media). In most cases this just casts the object to AsyncMedia, since most media returned from MediaManager already implement this interface. In cases where the media doesn’t already implement AsyncMedia, it will return an Async wrapper around the media.

Nested types

enum AsyncMedia.StateAn enum to represent the state of a media object.
enum AsyncMedia.MediaErrorTypeEnum encapsulating the different types of media errors that can occur.
class AsyncMedia.MediaStateChangeEventEncapsulates a state-change event on a Media object.
class AsyncMedia.MediaExceptionEncapsulates a media exception.
class AsyncMedia.MediaErrorEventEncapsulates a media error event.
class AsyncMedia.PlayRequestAn async resource used to track the progress of a playAsync() request.
class AsyncMedia.PauseRequestAn async resource used to track the progress of a pauseAsync() request.

Methods

public abstract AsyncMedia.State getState()Gets the current state of the media object.
public abstract void addMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)Adds a listener to be notified when the state of the media changes.
public abstract void removeMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)Removes a listener so that it will no longer be notified of state changes.
public abstract void addMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)Adds a listener to be notified when an error occurs in the media.
public abstract void removeMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)Removes a listener so that it will no longer be notified of errors.
public abstract void addMediaCompletionHandler(Runnable onComplete)Adds a callback to be run when the media has played to completion.
public abstract AsyncMedia.PlayRequest playAsync()Initiates a play request.
public abstract AsyncMedia.PauseRequest pauseAsync()Initiates a pause request.

Inherited fields

Inherited methods

Method details

getState

public abstract AsyncMedia.State getState()
Gets the current state of the media object.

Returns

The state of the media object.

addMediaStateChangeListener

public abstract void addMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)
Adds a listener to be notified when the state of the media changes.

Parameters

l ActionListener<AsyncMedia.MediaStateChangeEvent>
Listener

removeMediaStateChangeListener

public abstract void removeMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)
Removes a listener so that it will no longer be notified of state changes.

Parameters

l ActionListener<AsyncMedia.MediaStateChangeEvent>
Listener

addMediaErrorListener

public abstract void addMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)
Adds a listener to be notified when an error occurs in the media.

Parameters

l ActionListener<AsyncMedia.MediaErrorEvent>
Listener

removeMediaErrorListener

public abstract void removeMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)
Removes a listener so that it will no longer be notified of errors.

Parameters

l ActionListener<AsyncMedia.MediaErrorEvent>
Listener

addMediaCompletionHandler

public abstract void addMediaCompletionHandler(Runnable onComplete)
Adds a callback to be run when the media has played to completion.

playAsync

public abstract AsyncMedia.PlayRequest playAsync()
Initiates a play request. Returns immediately without blocking. Caller can use the returned PlayRequest object to be notified when playing has actually started.

pauseAsync

public abstract AsyncMedia.PauseRequest pauseAsync()
Initiates a pause request. Returns immediately without blocking. Caller can use the returned PauseRequest object to be notified when media has actually paused.