|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.caprica.vlcj.player.MediaPlayer
public abstract class MediaPlayer
Media player implementation.
This is the main class that developers working with VLCJ are expected to use.
This implementation provides the following functions:
The basic life-cycle is:
// Set some options for libvlc String[] libvlcArgs = {...add options here...}; // Create a factory MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs); // Create a full-screen strategy FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame); // Create a media player instance for the run-time operating system EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy); // Set standard options as needed to be applied to all subsequently played media items String[] standardMediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.setStandardMediaOptions(standardMediaOptions); // Add a component to be notified of player events mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {...add implementation here...}); // Create and set a new component to display the rendered video (not shown: add the Canvas to a Frame) Canvas videoSurface = new Canvas(); mediaPlayer.setVideoSurface(videoSurface); // Play a particular item, with options if necessary String mediaPath = "/path/to/some/movie.mpg"; String[] mediaOptions = {}; mediaPlayer.playMedia(mediaPath, mediaOptions); // Do some interesting things in the application ... // Cleanly dispose of the media player instance and any associated native resources mediaPlayer.release(); // Cleanly dispose of the media player factory and any associated native resources mediaPlayerFactory.release();With regard to overlaying logos there are three approaches.
The first way is to specify standard options for the media player - this will set the logo for any subsequently played media item, for example:
String[] standardMediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.setStandardMediaOptions(standardMediaOptions);The second way is to specify options when playing the media item, for example:
String[] mediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; mediaPlayer.playMedia(mediaPath, mediaOptions);The final way is to use the methods of this class to set various logo properties, for example:
mediaPlayer.setLogoFile("vlcj-logo.png"); mediaPlayer.setLogoOpacity(25); mediaPlayer.setLogoLocation(10, 10); mediaPlayer.enableLogo(true);For this latter method, it is not possible to enable the logo until after the video has started playing. There is also a noticeable stutter in video play-back when enabling the logo filter in this way.
With regard to overlaying marquees, again there are three approaches (similar to those for logos).
In this instance only the final way showing the usage of the API is used, for example:
mediaPlayer.setMarqueeText("VLCJ is quite good"); mediaPlayer.setMarqueeSize(60); mediaPlayer.setMarqueeOpacity(70); mediaPlayer.setMarqueeColour(Color.green); mediaPlayer.setMarqueeTimeout(3000); mediaPlayer.setMarqueeLocation(300, 400); mediaPlayer.enableMarquee(true);With regard to video adjustment controls, after the video has started playing:
mediaPlayer.setAdjustVideo(true); mediaPlayer.setGamma(0.9f); mediaPlayer.setHue(10);Some media when played may cause one or more media sub-items to created. These sub-items subsequently need to be played. The media player can be set to automatically play these sub-items via
setPlaySubItems(boolean)
,
otherwise playNextSubItem()
can be invoked in response to a
MediaPlayerEventListener#finished()
event.
Field Summary | |
---|---|
protected LibVlc |
libvlc
|
Constructor Summary | |
---|---|
MediaPlayer(libvlc_instance_t instance)
Create a new media player. |
Method Summary | |
---|---|
void |
addMediaOptions(java.lang.String... mediaOptions)
Add options to the current media. |
void |
addMediaPlayerEventListener(MediaPlayerEventListener listener)
Add a component to be notified of media player events. |
boolean |
canPause()
|
void |
cycleSpu()
Select the next sub-title track (or disable sub-titles). |
void |
enableLogo(boolean enable)
Enable/disable the logo. |
void |
enableMarquee(boolean enable)
Enable/disable the marquee. |
java.lang.String |
getAspectRatio()
|
int |
getAudioChannel()
Get the current audio channel. |
long |
getAudioDelay()
Get the audio delay. |
java.util.List<TrackDescription> |
getAudioDescriptions()
Get the audio track descriptions. |
int |
getAudioTrack()
Get the current audio track. |
int |
getAudioTrackCount()
Get the number of available audio tracks. |
float |
getBrightness()
Get the current video brightness. |
int |
getChapter()
Get the current chapter. |
int |
getChapterCount()
Get the chapter count. |
java.util.List<java.lang.String> |
getChapterDescriptions(int title)
Get the chapter descriptions for a title. |
float |
getContrast()
Get the current video contrast. |
java.lang.String |
getCropGeometry()
|
float |
getFps()
|
float |
getGamma()
Get the current video gamma. |
int |
getHue()
Get the current video hue. |
long |
getLength()
Get the length of the current media item. |
libvlc_state_t |
getMediaPlayerState()
|
libvlc_state_t |
getMediaState()
|
libvlc_media_stats_t |
getMediaStatistics()
Get the current media statistics. |
float |
getPosition()
Get the current play-back position. |
float |
getRate()
Get the current video play rate. |
float |
getSaturation()
Get the current video saturation. |
float |
getScale()
|
java.awt.image.BufferedImage |
getSnapshot()
Get a snapshot of the currently playing video. |
int |
getSpu()
Get the current sub-title track. |
int |
getSpuCount()
Get the number of sub-pictures/sub-titles. |
java.util.List<TrackDescription> |
getSpuDescriptions()
Get the sub-title track descriptions. |
long |
getTime()
Get the current play-back time. |
int |
getTitle()
Get the current title. |
int |
getTitleCount()
Get the number of titles. |
java.util.List<TrackDescription> |
getTitleDescriptions()
Get the title descriptions. |
java.util.List<TrackDescription> |
getVideoDescriptions()
Get the video (i.e. |
java.awt.Dimension |
getVideoDimension()
Get the video size. |
int |
getVideoOutputs()
Get the number of video outputs for the media player. |
int |
getVideoTrack()
Get the current video track. |
int |
getVideoTrackCount()
Get the number of available video tracks. |
int |
getVolume()
Get the current volume. |
boolean |
isAdjustVideo()
Test whether or not the video adjustments are enabled. |
boolean |
isMute()
Test whether or not the volume is currently muted. |
boolean |
isPlayable()
|
boolean |
isPlaying()
|
boolean |
isSeekable()
|
libvlc_media_player_t |
mediaPlayerInstance()
Provide access to the native media player instance. |
void |
menuActivate()
Requires vlc 1.2.0 or later. |
void |
menuDown()
Requires vlc 1.2.0 or later. |
void |
menuLeft()
Requires vlc 1.2.0 or later. |
void |
menuRight()
Requires vlc 1.2.0 or later. |
void |
menuUp()
Requires vlc 1.2.0 or later. |
void |
mute()
Toggle volume mute. |
void |
mute(boolean mute)
Mute or un-mute the volume. |
void |
nextChapter()
Jump to the next chapter. |
void |
nextFrame()
Advance one frame. |
protected void |
onAfterRelease()
Allow sub-classes to clean-up. |
protected void |
onBeforePlay()
Allow sub-classes to do something just before the video is started. |
void |
pause()
Pause play-back. |
void |
play()
Begin play-back. |
void |
playMedia(java.lang.String mrl)
Play a new media item. |
void |
playMedia(java.lang.String mrl,
java.lang.String... mediaOptions)
Play a new media item, with options. |
boolean |
playNextSubItem()
Play the next sub-item (if there is one). |
void |
prepareMedia(java.lang.String mrl)
Prepare a new media item for play-back, but do not begin playing. |
void |
prepareMedia(java.lang.String mrl,
java.lang.String... mediaOptions)
Prepare a new media item for play-back, but do not begin playing. |
void |
previousChapter()
Jump to the previous chapter. |
void |
release()
Release the media player, freeing all associated (including native) resources. |
void |
removeMediaPlayerEventListener(MediaPlayerEventListener listener)
Remove a component that was previously interested in notifications of media player events. |
void |
saveSnapshot()
Save a snapshot of the currently playing video. |
void |
saveSnapshot(java.io.File file)
Save a snapshot of the currently playing video. |
void |
selectAudioOutput(java.lang.String outputName)
Set the desired audio output. |
void |
setAdjustVideo(boolean adjustVideo)
Enable/disable the video adjustments. |
void |
setAspectRatio(java.lang.String aspectRatio)
|
void |
setAudioChannel(int channel)
Set the audio channel. |
void |
setAudioDelay(long delay)
Set the audio delay. |
void |
setAudioTrack(int track)
Set a new audio track to play. |
void |
setBrightness(float brightness)
Set the video brightness. |
void |
setChapter(int chapterNumber)
Set the chapter. |
void |
setContrast(float contrast)
Set the video contrast. |
void |
setCropGeometry(java.lang.String cropGeometry)
Set the crop geometry. |
void |
setDeinterlace(java.lang.String deinterlaceMode)
Set the de-interlace filter to use. |
void |
setEnableKeyInputHandling(boolean enable)
|
void |
setEnableMouseInputHandling(boolean enable)
|
void |
setGamma(float gamma)
Set the video gamma. |
void |
setHue(int hue)
Set the video hue. |
void |
setLogoFile(java.lang.String logoFile)
Set the logo file. |
void |
setLogoLocation(int x,
int y)
Set the logo location. |
void |
setLogoOpacity(float opacity)
Set the logo opacity. |
void |
setLogoOpacity(int opacity)
Set the logo opacity. |
void |
setLogoPosition(libvlc_logo_position_e position)
Set the logo position. |
void |
setMarqueeColour(java.awt.Color colour)
Set the marquee colour. |
void |
setMarqueeColour(int colour)
Set the marquee colour. |
void |
setMarqueeLocation(int x,
int y)
Set the marquee location. |
void |
setMarqueeOpacity(float opacity)
Set the marquee opacity. |
void |
setMarqueeOpacity(int opacity)
Set the marquee opacity. |
void |
setMarqueeSize(int size)
Set the marquee size. |
void |
setMarqueeText(java.lang.String text)
Set the marquee text. |
void |
setMarqueeTimeout(int timeout)
Set the marquee timeout. |
void |
setPause(boolean pause)
Pause/resume. |
void |
setPlaySubItems(boolean playSubItems)
Set whether or not the media player should automatically play media sub- items. |
void |
setPosition(float position)
Jump to a specific position. |
int |
setRate(float rate)
Set the video play rate. |
void |
setSaturation(float saturation)
Set the video saturation. |
void |
setScale(float factor)
|
void |
setSpu(int spu)
Set the current sub-title track. |
void |
setStandardMediaOptions(java.lang.String... options)
Set standard media options for all media items subsequently played. |
void |
setTime(long time)
Jump to a specific moment. |
void |
setTitle(int title)
Set a new title to play. |
void |
setVideoTrack(int track)
Set a new video track to play. |
void |
setVolume(int volume)
Set the volume. |
void |
skip(float delta)
Skip forward or backward by a change in position. |
void |
skip(long delta)
Skip forward or backward by a period of time. |
void |
stop()
Stop play-back. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final LibVlc libvlc
Constructor Detail |
---|
public MediaPlayer(libvlc_instance_t instance)
instance
- Method Detail |
---|
public void addMediaPlayerEventListener(MediaPlayerEventListener listener)
listener
- component to notifypublic void removeMediaPlayerEventListener(MediaPlayerEventListener listener)
listener
- component to stop notifyingpublic void setStandardMediaOptions(java.lang.String... options)
This will not affect any currently playing media item.
options
- options to apply to all subsequently played media itemspublic void playMedia(java.lang.String mrl)
The new media will begin play-back immediately.
mrl
- media resource locatorpublic void playMedia(java.lang.String mrl, java.lang.String... mediaOptions)
The new media will begin play-back immediately.
mrl
- media resource locatormediaOptions
- media item optionspublic void prepareMedia(java.lang.String mrl)
mrl
- media resource locatorpublic void prepareMedia(java.lang.String mrl, java.lang.String... mediaOptions)
mrl
- media resource locatormediaOptions
- media item optionspublic void addMediaOptions(java.lang.String... mediaOptions)
mediaOptions
- media optionspublic void setPlaySubItems(boolean playSubItems)
playSubItems
- true
to automatically play sub-items, otherwise false
public boolean playNextSubItem()
true
if there is a sub-item, otherwise false
public boolean isPlayable()
public boolean isPlaying()
public boolean isSeekable()
public boolean canPause()
public long getLength()
public long getTime()
public float getPosition()
public float getFps()
public float getRate()
public int getVideoOutputs()
public java.awt.Dimension getVideoDimension()
The video dimensions are not available until after the video has started playing.
null
public java.lang.String getAspectRatio()
public float getScale()
public java.lang.String getCropGeometry()
public libvlc_media_stats_t getMediaStatistics()
Statistics are only updated if the video is playing.
public libvlc_state_t getMediaState()
public libvlc_state_t getMediaPlayerState()
public int getTitleCount()
public int getTitle()
public void setTitle(int title)
title
- title numberpublic int getVideoTrackCount()
public int getVideoTrack()
This does not return the id of the track,
see getVideoDescriptions()
.
public void setVideoTrack(int track)
This does not take the track number returned from getVideoTrack()
,
rather it takes the track id obtained from
see getVideoDescriptions()
.
track
- track id, or -1 to disable the videopublic int getAudioTrackCount()
public int getAudioTrack()
public void setAudioTrack(int track)
track
- track numberpublic void play()
If called when the play-back is paused, the play-back will resume from the current position.
public void stop()
A subsequent play will play-back from the start.
public void setPause(boolean pause)
Requires vlc 1.1.1 or later.
pause
- true to pause, false to play/resumepublic void pause()
If the play-back is currently paused it will begin playing.
public void nextFrame()
public void skip(long delta)
delta
- time period, in millisecondspublic void skip(float delta)
delta
- public void setTime(long time)
time
- time since the beginning, in millisecondspublic void setPosition(float position)
position
- position value, a percentage (e.g. 0.15 is 15%)public int setRate(float rate)
Some media protocols are not able to change the rate.
rate
- rate, where 1.0 is normal speed, 0.5 is half speed, 2.0 is double speed and so on
public void setAspectRatio(java.lang.String aspectRatio)
aspectRatio
- public void setScale(float factor)
factor
- public void setCropGeometry(java.lang.String cropGeometry)
The format for the crop geometry is one of:
mediaPlayer.setCropGeometry("4:3"); mediaPlayer.setCropGeometry("719x575+0+0"); mediaPlayer.setCropGeometry("6:10:6:10");
cropGeometry
- formatted string describing the desired crop geometrypublic void selectAudioOutput(java.lang.String outputName)
outputName
- name of the desired audio outputpublic void mute()
public void mute(boolean mute)
mute
- true
to mute the volume, false
to un-mute itpublic boolean isMute()
true
if the volume is muted, false
if the volume is not mutedpublic int getVolume()
public void setVolume(int volume)
volume
- volume, in the range 0 to 200 where 200 is full volumepublic int getAudioChannel()
libvlc_audio_output_channel_t
.
Warning this API is subject to change.
public void setAudioChannel(int channel)
libvlc_audio_output_channel_t
.
Warning this API is subject to change.
channel
- channelpublic long getAudioDelay()
public void setAudioDelay(long delay)
The audio delay is set for the current item only and will be reset to zero each time the media changes.
delay
- desired audio delay, in microsecondspublic int getChapterCount()
public int getChapter()
public void setChapter(int chapterNumber)
chapterNumber
- chapter number, where zero is the first chapterpublic void nextChapter()
If the play-back is already at the last chapter, this will have no effect.
public void previousChapter()
If the play-back is already at the first chapter, this will have no effect.
public void menuActivate()
public void menuUp()
public void menuDown()
public void menuLeft()
public void menuRight()
public int getSpuCount()
public int getSpu()
public void setSpu(int spu)
spu
- sub-title number, or -1 for nonepublic void cycleSpu()
public java.util.List<TrackDescription> getTitleDescriptions()
public java.util.List<TrackDescription> getVideoDescriptions()
public java.util.List<TrackDescription> getAudioDescriptions()
public java.util.List<TrackDescription> getSpuDescriptions()
public java.util.List<java.lang.String> getChapterDescriptions(int title)
title
- title number TODO is it number or index?
public void saveSnapshot()
The snapshot will be created in the user's home directory and be assigned a filename based on the current time.
public void saveSnapshot(java.io.File file)
Any missing directory path will be created if it does not exist.
file
- file to contain the snapshotpublic java.awt.image.BufferedImage getSnapshot()
This implementation uses the native libvlc method to save a snapshot of the currently playing video. This snapshot is saved to a temporary file and then the resultant image is loaded from the file.
The size of the image will be that produced by the libvlc native snapshot function.
public void enableLogo(boolean enable)
The logo will not be enabled if there is currently no video being played.
enable
- true
to show the logo, false
to hide itpublic void setLogoOpacity(int opacity)
opacity
- opacity in the range 0 to 255 where 255 is fully opaquepublic void setLogoOpacity(float opacity)
opacity
- opacity percentage in the range 0.0 to 1.0 where 1.0 is fully opaquepublic void setLogoLocation(int x, int y)
x
- x co-ordinate for the top left of the logoy
- y co-ordinate for the top left of the logopublic void setLogoPosition(libvlc_logo_position_e position)
position
- positionpublic void setLogoFile(java.lang.String logoFile)
logoFile
- logo file namepublic void enableMarquee(boolean enable)
The marquee will not be enabled if there is currently no video being played.
enable
- true
to show the marquee, false
to hide itpublic void setMarqueeText(java.lang.String text)
text
- textpublic void setMarqueeColour(java.awt.Color colour)
colour
- colour, any alpha component will be masked offpublic void setMarqueeColour(int colour)
colour
- RGB colour valuepublic void setMarqueeOpacity(int opacity)
opacity
- opacity in the range 0 to 100 where 255 is fully opaquepublic void setMarqueeOpacity(float opacity)
opacity
- opacity percentage in the range 0.0 to 1.0 where 1.0 is fully opaquepublic void setMarqueeSize(int size)
size
- size, height of the marquee text in pixelspublic void setMarqueeTimeout(int timeout)
timeout
- timeout, in millisecondspublic void setMarqueeLocation(int x, int y)
x
- x co-ordinate for the top left of the marqueey
- y co-ordinate for the top left of the marqueepublic void setDeinterlace(java.lang.String deinterlaceMode)
deinterlaceMode
- mode, or null to disable the de-interlace filterpublic void setAdjustVideo(boolean adjustVideo)
The video adjustment controls must be enabled after the video has started playing.
Requires vlc 1.1.1 or later.
adjustVideo
- true if the video adjustments are enabled, otherwise falsepublic boolean isAdjustVideo()
Requires vlc 1.1.1 or later.
public float getContrast()
Requires vlc 1.1.1 or later.
public void setContrast(float contrast)
Video adjustments must be enabled for this to have any effect. Requires vlc 1.1.1 or later.
contrast
- contrast value, in the range from 0.0 to 2.0public float getBrightness()
Requires vlc 1.1.1 or later.
public void setBrightness(float brightness)
Video adjustments must be enabled for this to have any effect.
Requires vlc 1.1.1 or later.
brightness
- brightness value, in the range from 0.0 to 2.0public int getHue()
Requires vlc 1.1.1 or later.
public void setHue(int hue)
Video adjustments must be enabled for this to have any effect.
Requires vlc 1.1.1 or later.
hue
- hue value, in the range from 0 to 360public float getSaturation()
Requires vlc 1.1.1 or later.
public void setSaturation(float saturation)
Video adjustments must be enabled for this to have any effect.
Requires vlc 1.1.1 or later.
saturation
- saturation value, in the range from 0.0 to 3.0public float getGamma()
Requires vlc 1.1.1 or later.
public void setGamma(float gamma)
Video adjustments must be enabled for this to have any effect.
Requires vlc 1.1.1 or later.
gamma
- gamma, in the range from 0.01 to 10.0public void setEnableMouseInputHandling(boolean enable)
enable
- public void setEnableKeyInputHandling(boolean enable)
enable
- public final void release()
public final libvlc_media_player_t mediaPlayerInstance()
protected void onBeforePlay()
protected void onAfterRelease()
|
(C)2010 Caprica Software Limited | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |