Class AbstractMedia
java.lang.Object
com.codename1.media.AbstractMedia
- All Implemented Interfaces:
AsyncMedia, Media
An abstract base class for AsyncMedia. Most media returned from
MediaManager will
be descendants of this class.-
Nested Class Summary
Nested classes/interfaces inherited from interface AsyncMedia
AsyncMedia.MediaErrorEvent, AsyncMedia.MediaErrorType, AsyncMedia.MediaException, AsyncMedia.MediaStateChangeEvent, AsyncMedia.PauseRequest, AsyncMedia.PlayRequest, AsyncMedia.StateModifier and TypeInterfaceDescriptionstatic classEncapsulates a media error event.static enumEnum encapsulating the different types of media errors that can occur.static classEncapsulates a media exception.static classEncapsulates a state-change event on a Media object.static classAn async resource used to track the progress of a pauseAsync() request.static classAn async resource used to track the progress of a playAsync() request.static enumAn enum to represent the state of a media object. -
Field Summary
Fields inherited from interface Media
VARIABLE_ANDROID_SEEK_PREVIEW_WORKAROUND, VARIABLE_BACKGROUND_ALBUM_COVER, VARIABLE_BACKGROUND_ARTIST, VARIABLE_BACKGROUND_DURATION, VARIABLE_BACKGROUND_POSITION, VARIABLE_BACKGROUND_SUPPORTED, VARIABLE_BACKGROUND_TITLE, VARIABLE_NATIVE_CONTRLOLS_EMBEDDEDModifier and TypeFieldDescriptionstatic final StringOptional boolean flag to enable an Android-specific workaround for flaky black-frame previews afterMedia.setTime(int)on paused video.static final StringWrite only variable that can be used with setVariable to pass the album cover Image to the native layer so the currently playing media title will be displayed in the lock screen where applicablestatic final StringWrite only variable that can be used with setVariable to pass the artist name to the native layer so the currently playing media title will be displayed in the lock screen where applicablestatic final StringWrite only variable that can be used with setVariable to pass the duration for the media as a Long object to the native layer so the currently playing media title will be displayed in the lock screen where applicablestatic final StringWrite only variable that can be used with setVariable to pass the position in the media (Long object) to the native layer so the currently playing media title will be displayed in the lock screen where applicablestatic final StringRead only variable that can be used with getVariable to query whether the native layer supports displaying the currently playing media information in the lock screen.static final StringWrite only variable that can be used with setVariable to pass a title for the native layer so the currently playing media title will be displayed in the lock screen where applicablestatic final StringWrite-only variable that can be used with getVariable() to set whether this video should include embedded native controls. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMediaCompletionHandler(Runnable onComplete) Adds a callback to be run when the media has played to completion.voidAdds a listener to be notified when an error occurs in the media.voidAdds a listener to be notified when the state of the media changes.protected AsyncMedia.MediaErrorEventFires a media error event to registered listeners.protected AsyncMedia.MediaStateChangeEventfireMediaStateChange(AsyncMedia.State newState) Fires a media state change event to the registered state change listeners.getState()Gets the current state of the media object.final voidpause()Pauses (actually stops) the playback or the recording of the media fileInitiates a pause request.protected abstract voidInitiates a pause request on the media.final voidplay()Starts playing or recording the media fileInitiates a play request.protected abstract voidplayImpl()Initiates a play request on the media.voidRemoves a listener so that it will no longer be notified of errors.voidRemoves a listener so that it will no longer be notified of state changes.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()booleanIndicates whether some other object is "equal to" this one.final ClassgetClass()Returns the runtime class of an object.inthashCode()Returns a hash code value for the object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.Methods inherited from interface Media
cleanup, getDuration, getTime, getVariable, getVideoComponent, getVolume, isFullScreen, isNativePlayerMode, isPlaying, isVideo, prepare, setFullScreen, setNativePlayerMode, setTime, setVariable, setVolumeModifier and TypeMethodDescriptionvoidcleanup()Stops the audio playback and cleans up the resources related to it immediately.intReturns the length in milliseconds of the audio file or -1 if not knownintgetTime()Returns the time in milliseconds in the audio file or -1 if not knowngetVariable(String key) Allows querying platform specific information from the media objectGets the VideoComponent of this Video.intReturns the media playback volume in percentagebooleanThis method returns true if this video is in full screen mode.booleanReturns true if this Video Media is in Native player mode.booleanReturns true if the media is currently playing or recordingbooleanisVideo()This method returns true if this is a Video Mediavoidprepare()Optional call that allows the caller to prepare the upcoming media player.voidsetFullScreen(boolean fullScreen) Sets the Media to be displayed full screen, make sure the getVideoComponent() is called on the Video Component is added to the current FormvoidsetNativePlayerMode(boolean nativePlayer) By calling this the Media (if it's a Video) will be played full screen on the native Player of the device.voidsetTime(int time) Sets the position in the audio file or doesn't effect if not supportedvoidsetVariable(String key, Object value) Allows for platform specific enhancements for media playbackvoidsetVolume(int vol) Sets the media playback volume in percentage
-
Constructor Details
-
AbstractMedia
public AbstractMedia()
-
-
Method Details
-
getState
Gets the current state of the media object.
Returns
The state of the media object.
- Specified by:
getStatein interfaceAsyncMedia
-
fireMediaStateChange
Fires a media state change event to the registered state change listeners.
Parameters
newState: The new state
Returns
The state change event.
-
addMediaStateChangeListener
Adds a listener to be notified when the state of the media changes.
Parameters
l: Listener
- Specified by:
addMediaStateChangeListenerin interfaceAsyncMedia
-
removeMediaStateChangeListener
Removes a listener so that it will no longer be notified of state changes.
Parameters
l: Listener
- Specified by:
removeMediaStateChangeListenerin interfaceAsyncMedia
-
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
Adds a listener to be notified when an error occurs in the media.
Parameters
l: Listener
- Specified by:
addMediaErrorListenerin interfaceAsyncMedia
-
removeMediaErrorListener
Removes a listener so that it will no longer be notified of errors.
Parameters
l: Listener
- Specified by:
removeMediaErrorListenerin interfaceAsyncMedia
-
addMediaCompletionHandler
Adds a callback to be run when the media has played to completion.
Parameters
onComplete
- Specified by:
addMediaCompletionHandlerin interfaceAsyncMedia
-
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:
playAsyncin interfaceAsyncMedia
-
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:
pauseAsyncin interfaceAsyncMedia
-
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
-
pause
-