Class AbstractMedia

java.lang.Object
com.codename1.media.AbstractMedia
All Implemented Interfaces:
AsyncMedia, Media

public abstract class AbstractMedia extends Object implements AsyncMedia
An abstract base class for AsyncMedia. Most media returned from MediaManager will be descendants of this class.
  • Constructor Details

    • AbstractMedia

      public AbstractMedia()
  • Method Details

    • getState

      public AsyncMedia.State getState()

      Gets the current state of the media object.

      Returns

      The state of the media object.

      Specified by:
      getState in interface AsyncMedia
    • fireMediaStateChange

      protected AsyncMedia.MediaStateChangeEvent fireMediaStateChange(AsyncMedia.State newState)

      Fires a media state change event to the registered state change listeners.

      Parameters
      • newState: The new state
      Returns

      The state change event.

    • addMediaStateChangeListener

      public void addMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)

      Adds a listener to be notified when the state of the media changes.

      Parameters
      • l: Listener
      Specified by:
      addMediaStateChangeListener in interface AsyncMedia
    • removeMediaStateChangeListener

      public void removeMediaStateChangeListener(ActionListener<AsyncMedia.MediaStateChangeEvent> l)

      Removes a listener so that it will no longer be notified of state changes.

      Parameters
      • l: Listener
      Specified by:
      removeMediaStateChangeListener in interface AsyncMedia
    • fireMediaError

      Fires a media error event to registered listeners.

      Parameters
      • ex: The MediaException to deliver
      Returns

      The MediaErrorEvent object sent to listeners.

      See also
      • #addMediaErrorListener(com.codename1.ui.events.ActionListener)

      • #removeMediaErrorListener(com.codename1.ui.events.ActionListener)

    • addMediaErrorListener

      public void addMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)

      Adds a listener to be notified when an error occurs in the media.

      Parameters
      • l: Listener
      Specified by:
      addMediaErrorListener in interface AsyncMedia
    • removeMediaErrorListener

      public void removeMediaErrorListener(ActionListener<AsyncMedia.MediaErrorEvent> l)

      Removes a listener so that it will no longer be notified of errors.

      Parameters
      • l: Listener
      Specified by:
      removeMediaErrorListener in interface AsyncMedia
    • addMediaCompletionHandler

      public void addMediaCompletionHandler(Runnable onComplete)

      Adds a callback to be run when the media has played to completion.

      Parameters
      • onComplete
      Specified by:
      addMediaCompletionHandler in interface AsyncMedia
    • playAsync

      public 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.
      Specified by:
      playAsync in interface AsyncMedia
    • pauseAsync

      public 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.
      Specified by:
      pauseAsync in interface AsyncMedia
    • playImpl

      protected abstract void playImpl()
      Initiates a play request on the media.
    • pauseImpl

      protected abstract void pauseImpl()
      Initiates a pause request on the media.
    • play

      public final void play()
      Starts playing or recording the media file
      Specified by:
      play in interface Media
    • pause

      public final void pause()
      Pauses (actually stops) the playback or the recording of the media file
      Specified by:
      pause in interface Media