Package org.videolan.libvlc
Class Media
- java.lang.Object
-
- org.videolan.libvlc.Media
-
- All Implemented Interfaces:
IMedia
,IVLCObject<IMedia.Event>
public class Media extends Object implements IMedia
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.videolan.libvlc.interfaces.IMedia
IMedia.AudioTrack, IMedia.Event, IMedia.EventListener, IMedia.Meta, IMedia.Parse, IMedia.ParsedStatus, IMedia.Slave, IMedia.State, IMedia.Stats, IMedia.SubtitleTrack, IMedia.Track, IMedia.Type, IMedia.UnknownTrack, IMedia.VideoTrack
-
-
Constructor Summary
Constructors Modifier Constructor Description Media(ILibVLC ILibVLC, AssetFileDescriptor afd)
Create a Media from libVLC and an AssetFileDescriptorMedia(ILibVLC ILibVLC, Uri uri)
Create a Media from libVLC and a UriMedia(ILibVLC ILibVLC, FileDescriptor fd)
Create a Media from libVLC and a FileDescriptorMedia(ILibVLC ILibVLC, String path)
Create a Media from libVLC and a local path starting with '/'.protected
Media(IMediaList ml, int index)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOption(String option)
Add an option to this Media.void
addSlave(IMedia.Slave slave)
Add a slave to the current media.void
clearSlaves()
Clear all slaves previously added byaddSlave(Slave)
or internally.protected void
finalize()
long
getDuration()
Get the duration of the media.long
getInstance()
ILibVLC
getLibVLC()
String
getMeta(int id)
Get a Meta.String
getMeta(int id, boolean force)
Get a Meta.IMedia.Slave[]
getSlaves()
Get a media's slave list The list will contain slaves parsed by VLC or previously added byaddSlave(Slave)
.IMedia.Stats
getStats()
Get the stats related to the playing mediaIMedia.Track[]
getTracks()
Get the list of tracks for all typesIMedia.Track[]
getTracks(int type)
Get the list of tracks for a given typeint
getType()
Get the type of the mediaUri
getUri()
Get the MRL associated with the Media.boolean
isParsed()
Returns true if the media is parsed This Media should be alive (not released).boolean
isReleased()
Returns true if native object is releasedprotected IMedia.Event
onEventNative(int eventType, long arg1, long arg2, float argf1, String args1)
Called when libvlc send events.protected void
onReleaseNative()
Called when native object is released (refcount is 0).boolean
parse()
Parse the media and local art synchronously.boolean
parse(int flags)
Parse the media synchronously with a flag.boolean
parseAsync()
Parse the media and local art asynchronously.boolean
parseAsync(int flags)
boolean
parseAsync(int flags, int timeout)
Parse the media asynchronously with a flag.void
release()
Release the native object if ref count is 1.boolean
retain()
Increment internal ref count of the native object.void
setDefaultMediaPlayerOptions()
Enable HWDecoder options if not already setprotected void
setEventListener(AbstractVLCEvent.Listener<T> listener)
Set an event listener.protected void
setEventListener(AbstractVLCEvent.Listener<T> listener, Handler handler)
Set an event listener and an executor Handlervoid
setEventListener(IMedia.EventListener listener)
void
setHWDecoderEnabled(boolean enabled, boolean force)
Add or remove hw acceleration media optionsMediaList
subItems()
Get the subItems MediaList associated with the Media.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.videolan.libvlc.interfaces.IVLCObject
getLibVLC, isReleased, release, retain
-
-
-
-
Constructor Detail
-
Media
public Media(ILibVLC ILibVLC, String path)
Create a Media from libVLC and a local path starting with '/'.- Parameters:
ILibVLC
- a valid libVLCpath
- an absolute local path
-
Media
public Media(ILibVLC ILibVLC, Uri uri)
Create a Media from libVLC and a Uri- Parameters:
ILibVLC
- a valid libVLCuri
- a valid RFC 2396 Uri
-
Media
public Media(ILibVLC ILibVLC, FileDescriptor fd)
Create a Media from libVLC and a FileDescriptor- Parameters:
ILibVLC
- a valid LibVLCfd
- file descriptor object
-
Media
public Media(ILibVLC ILibVLC, AssetFileDescriptor afd)
Create a Media from libVLC and an AssetFileDescriptor- Parameters:
ILibVLC
- a valid LibVLCafd
- asset file descriptor object
-
Media
protected Media(IMediaList ml, int index)
- Parameters:
ml
- Should not be released and lockedindex
- index of the Media from the MediaList
-
-
Method Detail
-
setEventListener
public void setEventListener(IMedia.EventListener listener)
- Specified by:
setEventListener
in interfaceIMedia
-
onEventNative
protected IMedia.Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1)
Called when libvlc send events.- Parameters:
eventType
- event typearg1
- first argumentarg2
- second argumentargf1
- first float argument- Returns:
- Event that will be dispatched to listeners
-
getUri
public Uri getUri()
Get the MRL associated with the Media.
-
getDuration
public long getDuration()
Get the duration of the media.- Specified by:
getDuration
in interfaceIMedia
-
subItems
public MediaList subItems()
Get the subItems MediaList associated with the Media. This Media should be alive (not released).- Specified by:
subItems
in interfaceIMedia
- Returns:
- subItems as a MediaList. This MediaList should be released with
IVLCObject.release()
.
-
parse
public boolean parse(int flags)
Parse the media synchronously with a flag. This Media should be alive (not released).- Specified by:
parse
in interfaceIMedia
- Parameters:
flags
- seeIMedia.Parse
- Returns:
- true in case of success, false otherwise.
-
parse
public boolean parse()
Parse the media and local art synchronously. This Media should be alive (not released).
-
parseAsync
public boolean parseAsync(int flags, int timeout)
Parse the media asynchronously with a flag. This Media should be alive (not released). To track when this is over you can listen toIMedia.Event.ParsedChanged
event (only if this methods returned true).- Specified by:
parseAsync
in interfaceIMedia
- Parameters:
flags
- seeIMedia.Parse
timeout
- maximum time allowed to preparse the media. If -1, the default "preparse-timeout" option will be used as a timeout. If 0, it will wait indefinitely. If > 0, the timeout will be used (in milliseconds).- Returns:
- true in case of success, false otherwise.
-
parseAsync
public boolean parseAsync(int flags)
- Specified by:
parseAsync
in interfaceIMedia
-
parseAsync
public boolean parseAsync()
Parse the media and local art asynchronously. This Media should be alive (not released).- Specified by:
parseAsync
in interfaceIMedia
- See Also:
parseAsync(int)
-
isParsed
public boolean isParsed()
Returns true if the media is parsed This Media should be alive (not released).
-
getTracks
public IMedia.Track[] getTracks(int type)
Get the list of tracks for a given type- Specified by:
getTracks
in interfaceIMedia
- Parameters:
type
- type defined byIMedia.Track.Type
- Returns:
- a track array or null. Each tracks can be casted to
IMedia.VideoTrack
,IMedia.AudioTrack
,IMedia.SubtitleTrack
, orIMedia.UnknownTrack
depending onMedia.type
-
getTracks
public IMedia.Track[] getTracks()
Get the list of tracks for all types
-
getMeta
public String getMeta(int id)
Get a Meta.- Specified by:
getMeta
in interfaceIMedia
- Parameters:
id
- seeIMedia.Meta
- Returns:
- meta or null if not found
-
getMeta
public String getMeta(int id, boolean force)
Get a Meta.- Specified by:
getMeta
in interfaceIMedia
- Parameters:
id
- seeIMedia.Meta
force
- force the native call to be done- Returns:
- meta or null if not found
-
setHWDecoderEnabled
public void setHWDecoderEnabled(boolean enabled, boolean force)
Add or remove hw acceleration media options- Specified by:
setHWDecoderEnabled
in interfaceIMedia
- Parameters:
enabled
- if true, hw decoder will be usedforce
- force hw acceleration even for unknown devices
-
setDefaultMediaPlayerOptions
public void setDefaultMediaPlayerOptions()
Enable HWDecoder options if not already set- Specified by:
setDefaultMediaPlayerOptions
in interfaceIMedia
-
addOption
public void addOption(String option)
Add an option to this Media. This Media should be alive (not released).
-
addSlave
public void addSlave(IMedia.Slave slave)
Add a slave to the current media. A slave is an external input source that may contains an additional subtitle track (like a .srt) or an additional audio track (like a .ac3). This function must be called before the media is parsed (viaparseAsync(int)
} or before the media is played (viaMediaPlayer.play()
)
-
clearSlaves
public void clearSlaves()
Clear all slaves previously added byaddSlave(Slave)
or internally.- Specified by:
clearSlaves
in interfaceIMedia
-
getSlaves
@Nullable public IMedia.Slave[] getSlaves()
Get a media's slave list The list will contain slaves parsed by VLC or previously added byaddSlave(Slave)
. The typical use case of this function is to save a list of slave in a database for a later use.
-
getStats
@Nullable public IMedia.Stats getStats()
Get the stats related to the playing media
-
onReleaseNative
protected void onReleaseNative()
Called when native object is released (refcount is 0). This is where you must release native resources.
-
isReleased
public boolean isReleased()
Returns true if native object is released- Specified by:
isReleased
in interfaceIVLCObject<T extends AbstractVLCEvent>
-
retain
public final boolean retain()
Increment internal ref count of the native object.- Specified by:
retain
in interfaceIVLCObject<T extends AbstractVLCEvent>
- Returns:
- true if media is retained
-
release
public final void release()
Release the native object if ref count is 1. After this call, native calls are not possible anymore. You can still call others methods to retrieve cached values. For example: if you parse, then release a media, you'll still be able to retrieve all Metas or Tracks infos.- Specified by:
release
in interfaceIVLCObject<T extends AbstractVLCEvent>
-
getLibVLC
public ILibVLC getLibVLC()
- Specified by:
getLibVLC
in interfaceIVLCObject<T extends AbstractVLCEvent>
-
setEventListener
protected void setEventListener(AbstractVLCEvent.Listener<T> listener)
Set an event listener. Events are sent via the android main thread.- Parameters:
listener
- seeAbstractVLCEvent.Listener
-
setEventListener
protected void setEventListener(AbstractVLCEvent.Listener<T> listener, Handler handler)
Set an event listener and an executor Handler- Parameters:
listener
- seeAbstractVLCEvent.Listener
handler
- Handler in which events are sent. If null, a handler will be created running on the main thread
-
getInstance
public long getInstance()
-
-