public class MediaPlayerFactory extends Object
The factory initialises a single libvlc instance and uses that to create media player instances.
If required, you can create multiple factory instances each with their own libvlc options.
You should release the factory when your application terminates to properly clean up native resources.
The factory also provides access to the native libvlc Logger and other resources such as the list of audio outputs, and the list of available audio and video filters.
Usage:
// Set some options for libvlc String[] libvlcArgs = {...add options here...}; // Create a factory instance (once), you can keep a reference to this MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs); // Create a full-screen strategy FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame); // Create a media player instance EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer(fullScreenStrategy); // Do some interesting things with the media player, like setting a video surface... ... // Release the media player mediaPlayer.release(); // Release the factory factory.release();You must make sure you keep a hard reference to the media player (and possibly other) objects created by this factory. If you allow a media player object to go out of scope, then unpredictable behaviour will occur (such as events no longer seeming to fire) even though the video playback continues (since that happens via native code). You may also likely suffer fatal JVM crashes.
It is always a better strategy to reuse media player instances, rather than repeatedly creating and destroying instances.
Constructor and Description |
---|
MediaPlayerFactory()
Create a new media player factory.
|
MediaPlayerFactory(LibVlc libvlc)
Create a new media player factory.
|
MediaPlayerFactory(LibVlc libvlc,
List<String> libvlcArgs)
Create a new media player factory.
|
MediaPlayerFactory(LibVlc libvlc,
String... libvlcArgs)
Create a new media player factory.
|
MediaPlayerFactory(List<String> libvlcArgs)
Create a new media player factory.
|
MediaPlayerFactory(String... libvlcArgs)
Create a new media player factory.
|
Modifier and Type | Method and Description |
---|---|
String |
changeset()
Get the source code change-set id used to build libvlc.
|
long |
clock()
Get the time as defined by LibVLC.
|
String |
compiler()
Get the compiler used to build libvlc.
|
List<ModuleDescription> |
getAudioFilters()
Get the available audio filters.
|
List<AudioOutput> |
getAudioOutputs()
Get the available audio outputs.
|
MediaMeta |
getMediaMeta(String mediaPath,
boolean parse)
Get local media meta data.
|
List<ModuleDescription> |
getVideoFilters()
Get the available video filters.
|
MediaDiscoverer |
newAudioMediaDiscoverer()
Create a new native audio media service discoverer.
|
DirectMediaPlayer |
newDirectMediaPlayer(BufferFormatCallback bufferFormatCallback,
RenderCallback renderCallback)
Create a new direct video rendering media player.
|
DirectMediaPlayer |
newDirectMediaPlayer(int width,
int height,
RenderCallback renderCallback)
Deprecated.
|
DirectMediaPlayer |
newDirectMediaPlayer(String format,
int width,
int height,
int pitch,
RenderCallback renderCallback)
Deprecated.
|
EmbeddedMediaPlayer |
newEmbeddedMediaPlayer()
Create a new embedded media player.
|
EmbeddedMediaPlayer |
newEmbeddedMediaPlayer(FullScreenStrategy fullScreenStrategy)
Create a new embedded media player.
|
HeadlessMediaPlayer |
newHeadlessMediaPlayer()
Create a new headless media player.
|
NativeLog |
newLog()
Create a new native log component.
|
MediaDiscoverer |
newMediaDiscoverer(String name)
Create a new native media service discoverer.
|
MediaList |
newMediaList()
Create a new media list for a play-list media player.
|
MediaListPlayer |
newMediaListPlayer()
Create a new play-list media player.
|
MediaManager |
newMediaManager()
Create a new media manager.
|
MediaDiscoverer |
newVideoMediaDiscoverer()
Create a new native video media service discoverer.
|
CanvasVideoSurface |
newVideoSurface(Canvas canvas)
Create a new video surface for a Canvas.
|
ComponentIdVideoSurface |
newVideoSurface(long componentId)
Create a new video surface for a native component id.
|
void |
release()
Release the native resources associated with this factory.
|
void |
setUserAgent(String userAgent)
Set the application name.
|
void |
setUserAgent(String userAgent,
String httpUserAgent)
Set the application name.
|
String |
version()
Get the libvlc version.
|
public MediaPlayerFactory()
If you want to enable logging or synchronisation of the native library interface you must use
MediaPlayerFactory(LibVlc)
and LibVlcFactory
.
This factory constructor will enforce a minimum required native library version check - if a suitable native library version is not found a RuntimeException will be thrown.
If you do not want to enforce this version check, use one of the other constructors that
accepts a LibVlc instance that you obtain from the LibVlcFactory
.
public MediaPlayerFactory(String... libvlcArgs)
If you want to enable logging or synchronisation of the native library interface you must use
MediaPlayerFactory(LibVlc)
and LibVlcFactory
.
This factory constructor will enforce a minimum required native library version check - if a suitable native library version is not found, a RuntimeException will be thrown.
If you do not want to enforce this version check, use one of the other constructors that
accepts a LibVlc instance that you obtain from the LibVlcFactory
.
Most initialisation arguments may be gleaned by invoking "vlc -H"
.
libvlcArgs
- initialisation arguments to pass to libvlcpublic MediaPlayerFactory(LibVlc libvlc)
Use LibVlcFactory
to get a reference to the native library.
libvlc
- interface to the native librarypublic MediaPlayerFactory(LibVlc libvlc, String... libvlcArgs)
Use LibVlcFactory
to get a reference to the native library.
libvlc
- interface to the native librarylibvlcArgs
- initialisation arguments to pass to libvlcpublic MediaPlayerFactory(List<String> libvlcArgs)
This is simply an alternate constructor for convenience, see
MediaPlayerFactory(String...)
.
libvlcArgs
- initialisation arguments to pass to libvlc, may be empty but must not be null
public MediaPlayerFactory(LibVlc libvlc, List<String> libvlcArgs)
Use LibVlcFactory
to get a reference to the native library.
This is simply an alternate constructor for convenience, see
MediaPlayerFactory(LibVlc, String...)
.
libvlc
- interface to the native librarylibvlcArgs
- initialisation arguments to pass to libvlc, may be empty but must not be null
public void release()
public void setUserAgent(String userAgent)
userAgent
- application namepublic void setUserAgent(String userAgent, String httpUserAgent)
userAgent
- application namehttpUserAgent
- application name for HTTPpublic List<AudioOutput> getAudioOutputs()
Each audio output has zero or more audio devices, each device having it's own unique identifier that can be used on a media player to set the select the required output device.
public List<ModuleDescription> getAudioFilters()
public List<ModuleDescription> getVideoFilters()
public EmbeddedMediaPlayer newEmbeddedMediaPlayer()
Full-screen will not be available, to enable full-screen support see
newEmbeddedMediaPlayer(FullScreenStrategy)
, or use an alternate mechanism to
manually set full-screen if needed.
public EmbeddedMediaPlayer newEmbeddedMediaPlayer(FullScreenStrategy fullScreenStrategy)
fullScreenStrategy
- full screen implementation, may be null
@Deprecated public DirectMediaPlayer newDirectMediaPlayer(int width, int height, RenderCallback renderCallback)
newDirectMediaPlayer(BufferFormatCallback, RenderCallback)
insteadThe pixel format used is "RV32" (a raw RGB format with padded alpha) and the pitch is width*4.
width
- width for the videoheight
- height for the videorenderCallback
- callback to receive the video frame data@Deprecated public DirectMediaPlayer newDirectMediaPlayer(String format, int width, int height, int pitch, RenderCallback renderCallback)
newDirectMediaPlayer(BufferFormatCallback, RenderCallback)
insteadwidth
- width for the videoheight
- height for the videoformat
- pixel format (e.g. RV15, RV16, RV24, RV32, RGBA, YUYV)pitch
- pitch, also known as striderenderCallback
- callback to receive the video frame datapublic DirectMediaPlayer newDirectMediaPlayer(BufferFormatCallback bufferFormatCallback, RenderCallback renderCallback)
bufferFormatCallback
- callback to set the desired buffer formatrenderCallback
- callback to receive the video frame datapublic HeadlessMediaPlayer newHeadlessMediaPlayer()
The head-less player is intended for audio media players or streaming server media players and may spawn a native video player window unless you set proper media options when playing media.
public MediaListPlayer newMediaListPlayer()
public CanvasVideoSurface newVideoSurface(Canvas canvas)
canvas
- canvaspublic ComponentIdVideoSurface newVideoSurface(long componentId)
componentId
- native component idpublic MediaList newMediaList()
public MediaMeta getMediaMeta(String mediaPath, boolean parse)
Note that requesting meta data may cause one or more HTTP connections to be made to external web-sites to attempt download of album art.
This method should not be invoked for non-local MRL's like streaming network addresses.
mediaPath
- path to the local mediaparse
- true
if the media should be parsed immediately; otherwise false
null
if the media could not be locatedpublic NativeLog newLog()
The native log requires vlc 2.1.0 or later.
null
if the native log is not availablepublic MediaDiscoverer newMediaDiscoverer(String name)
Not all media discoveres are supported on all platforms.
name
- name of the required service discoverer, e.g. "audio", "video".public MediaDiscoverer newAudioMediaDiscoverer()
This method is simply a convenient wrapper around newMediaDiscoverer(String)
.
public MediaDiscoverer newVideoMediaDiscoverer()
This should return for example video capture devices currently attached to the system.
This method is simply a convenient wrapper around newMediaDiscoverer(String)
.
The video discoverer may not be available on all platforms.
public long clock()
The time is not meaningful in the sense of what time is it, rather it is a monotonic clock with an arbitrary starting value.
public MediaManager newMediaManager()
public String version()
public String compiler()
public String changeset()
Copyright © 2009-2013 Caprica Software Limited. All Rights Reserved.