public class MediaPlayer
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MediaPlayer.Chapter |
static class |
MediaPlayer.Equalizer |
static class |
MediaPlayer.Event |
static interface |
MediaPlayer.EventListener |
static class |
MediaPlayer.Navigate |
static class |
MediaPlayer.Position |
static class |
MediaPlayer.ScaleType |
static class |
MediaPlayer.Title |
static class |
MediaPlayer.TrackDescription |
| Modifier and Type | Field and Description |
|---|---|
static int |
SURFACE_SCALES_COUNT |
| Constructor and Description |
|---|
MediaPlayer(LibVLC libVLC)
Create an empty MediaPlayer
|
MediaPlayer(Media media)
Create a MediaPlayer from a Media
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addSlave(int type,
java.lang.String path,
boolean select)
Add a slave (or subtitle) to the current media player.
|
boolean |
addSlave(int type,
android.net.Uri uri,
boolean select)
Add a slave (or subtitle) to the current media player.
|
void |
attachViews(VLCVideoLayout surfaceFrame,
DisplayManager dm,
boolean subtitles,
boolean textureView)
Attach a video layout to the player
|
boolean |
canDoPassthrough() |
void |
detachViews()
Detach the video layout
|
protected void |
finalize() |
boolean |
forceAudioDigitalEncodings(int[] encodings)
Convenient method for
setAudioOutputDevice(java.lang.String) |
java.lang.String |
getAspectRatio()
Get current video aspect ratio
|
long |
getAudioDelay()
Get the current audio delay.
|
int |
getAudioTrack()
Get the current audio track.
|
MediaPlayer.TrackDescription[] |
getAudioTracks()
Get the list of available audio tracks.
|
int |
getAudioTracksCount()
Get the number of available audio tracks.
|
int |
getChapter() |
MediaPlayer.Chapter[] |
getChapters(int title)
Get the full description of available chapters.
|
Media.VideoTrack |
getCurrentVideoTrack()
Get the current video track
|
long |
getLength()
Gets current movie's length in ms.
|
Media |
getMedia()
Get the Media used by this MediaPlayer.
|
int |
getPlayerState()
Get player state.
|
float |
getPosition()
Gets the movie position.
|
float |
getRate()
Get the current playback speed
|
float |
getScale()
Get the current video scaling factor
|
long |
getSpuDelay()
Get the current spu (subtitle) delay.
|
int |
getSpuTrack()
Get the current spu (subtitle) track.
|
MediaPlayer.TrackDescription[] |
getSpuTracks()
Get the list of available spu (subtitle) tracks.
|
int |
getSpuTracksCount()
Get the number of available spu (subtitle) tracks.
|
long |
getTime()
Gets the current movie time (in ms).
|
int |
getTitle() |
MediaPlayer.Title[] |
getTitles()
Get the full description of available titles.
|
MediaPlayer.ScaleType |
getVideoScale()
Get the current video scale type
|
int |
getVideoTrack()
Get the current video track.
|
MediaPlayer.TrackDescription[] |
getVideoTracks()
Get the list of available video tracks.
|
int |
getVideoTracksCount()
Get the number of available video tracks.
|
IVLCVout |
getVLCVout()
Get the IVLCVout helper.
|
int |
getVolume()
Gets volume as integer
|
boolean |
hasMedia()
Is a media in use by this MediaPlayer
|
boolean |
isPlaying()
Returns true if any media is playing
|
boolean |
isReleased()
Returns true if native object is released
|
boolean |
isSeekable()
Returns true if any media is seekable
|
void |
navigate(int navigate) |
int |
nextChapter() |
protected MediaPlayer.Event |
onEventNative(int eventType,
long arg1,
long arg2,
float argf1)
Called when libvlc send events.
|
protected void |
onReleaseNative()
Called when native object is released (refcount is 0).
|
void |
pause()
Pauses any playing media
|
void |
play()
Play the media
|
void |
play(android.content.res.AssetFileDescriptor afd)
Load an asset and starts playback
|
void |
play(Media media)
Starts playback from an already prepared Media
|
void |
play(java.lang.String path)
Play a media via its mrl
|
void |
play(android.net.Uri uri)
Play a media via its Uri
|
void |
playAsset(android.content.Context context,
java.lang.String assetFilename)
Load an asset and starts playback
|
int |
previousChapter() |
void |
release()
Release the native object if ref count is 1.
|
boolean |
retain()
Increment internal ref count of the native object.
|
void |
setAspectRatio(java.lang.String aspect)
Set new video aspect ratio.
|
boolean |
setAudioDelay(long delay)
Set current audio delay.
|
boolean |
setAudioDigitalOutputEnabled(boolean enabled)
Enable or disable Digital Output
Works only with AudioTrack AudioOutput.
|
boolean |
setAudioOutput(java.lang.String aout)
Selects an audio output module.
|
boolean |
setAudioOutputDevice(java.lang.String id)
Configures an explicit audio output device.
|
boolean |
setAudioTrack(int index)
Set the audio track.
|
void |
setChapter(int chapter) |
boolean |
setEqualizer(MediaPlayer.Equalizer equalizer)
Apply new equalizer settings to a media player.
|
void |
setEventListener(MediaPlayer.EventListener listener) |
protected void |
setEventListener(VLCEvent.Listener<T> listener)
Set an event listener.
|
protected void |
setEventListener(VLCEvent.Listener<T> listener,
android.os.Handler handler)
Set an event listener and an executor Handler
|
void |
setMedia(Media media)
Set a Media
|
void |
setPosition(float pos)
Sets the movie position.
|
void |
setRate(float rate)
Sets the speed of playback (1 being normal speed, 2 being twice as fast)
|
int |
setRenderer(RendererItem item)
Set a renderer
|
void |
setScale(float scale)
Set the video scaling factor
That is the ratio of the number of pixels on screen to the number of pixels in the original
decoded video in each dimension.
|
boolean |
setSpuDelay(long delay)
Set current spu (subtitle) delay.
|
boolean |
setSpuTrack(int index)
Set the spu (subtitle) track.
|
long |
setTime(long time)
Sets the movie time (in ms), if any media is being played.
|
void |
setTitle(int title) |
void |
setVideoScale(MediaPlayer.ScaleType type)
Set the video scale type, by default, scaletype is set to ScaleType.SURFACE_BEST_FIT
|
void |
setVideoTitleDisplay(int position,
int timeout)
Set if, and how, the video title will be shown when media is played
|
boolean |
setVideoTrack(int index)
Set the video track.
|
void |
setVideoTrackEnabled(boolean enabled)
Set the enabled state of the video track
|
int |
setVolume(int volume)
Sets volume as integer
|
void |
stop()
Stops the playing media
|
void |
updateVideoSurfaces()
Update the video surfaces, either to switch from one to another or to resize it
|
boolean |
updateViewpoint(float yaw,
float pitch,
float roll,
float fov,
boolean absolute)
Update the video viewpoint information
|
public MediaPlayer(LibVLC libVLC)
libVLC - a valid libVLCpublic MediaPlayer(Media media)
media - a valid Media objectpublic IVLCVout getVLCVout()
public void attachViews(VLCVideoLayout surfaceFrame, DisplayManager dm, boolean subtitles, boolean textureView)
surfaceFrame - VLCVideoLayout in which the video will be displayeddm - Optional DisplayManager to help switch between renderers, primary and secondary displayssubtitles - Whether you wish to show subtitlestextureView - If true, VLCVideoLayout will use a TextureView instead of a SurfaceViewpublic void detachViews()
public void updateVideoSurfaces()
public void setVideoScale(MediaPlayer.ScaleType type)
{@link - ScaleType} to rule the video surface fillingpublic MediaPlayer.ScaleType getVideoScale()
MediaPlayer.ScaleType used by MediaPlayerpublic void setMedia(Media media)
media - a valid Media objectpublic int setRenderer(RendererItem item)
item - RendererItem. if null VLC play on default outputpublic boolean hasMedia()
public Media getMedia()
release().public void play()
public void playAsset(android.content.Context context,
java.lang.String assetFilename)
throws java.io.IOException
context - An application context, mandatory to access assetsassetFilename - relative path of the asset in app assets folderjava.io.IOExceptionpublic void play(android.content.res.AssetFileDescriptor afd)
afd - The AssetFileDescriptor to playpublic void play(java.lang.String path)
path - Path of the media file to playpublic void play(android.net.Uri uri)
uri - Uri of the media to playpublic void play(Media media)
media - The Media to playpublic void stop()
public void setVideoTitleDisplay(int position,
int timeout)
position - see MediaPlayer.Positiontimeout - public float getScale()
public void setScale(float scale)
scale - the scaling factor, or zeropublic java.lang.String getAspectRatio()
public void setAspectRatio(java.lang.String aspect)
aspect - new video aspect-ratio or NULL to reset to defaultpublic boolean updateViewpoint(float yaw,
float pitch,
float roll,
float fov,
boolean absolute)
yaw - View point yaw in degreespitch - View point pitch in degreesroll - View point roll in degreesfov - Field of view in degrees (default 80.0f)absolute - if true replace the old viewpoint with the new one. If false,
increase/decrease it.public boolean setAudioOutput(java.lang.String aout)
public boolean setAudioDigitalOutputEnabled(boolean enabled)
setAudioOutputDevice(java.lang.String) was previously called, this method won't have any effects.enabled - true to enable Digital Outputpublic boolean forceAudioDigitalEncodings(int[] encodings)
setAudioOutputDevice(java.lang.String)encodings - list of encodings to play via passthrough (see AudioFormat.ENCODING_*),
null to don't force any.public boolean setAudioOutputDevice(java.lang.String id)
setAudioOutput(java.lang.String) and setAudioDigitalOutputEnabled(boolean)).public MediaPlayer.Title[] getTitles()
public MediaPlayer.Chapter[] getChapters(int title)
title - index of the title (if -1, use the current title)public int getVideoTracksCount()
public MediaPlayer.TrackDescription[] getVideoTracks()
public int getVideoTrack()
public boolean setVideoTrack(int index)
public void setVideoTrackEnabled(boolean enabled)
enabled - public Media.VideoTrack getCurrentVideoTrack()
public int getAudioTracksCount()
public MediaPlayer.TrackDescription[] getAudioTracks()
public int getAudioTrack()
public boolean setAudioTrack(int index)
public long getAudioDelay()
public boolean setAudioDelay(long delay)
delay - in microseconds.public int getSpuTracksCount()
public MediaPlayer.TrackDescription[] getSpuTracks()
public int getSpuTrack()
public boolean setSpuTrack(int index)
public long getSpuDelay()
public boolean setSpuDelay(long delay)
delay - in microseconds.public boolean setEqualizer(MediaPlayer.Equalizer equalizer)
MediaPlayer.Equalizer.create() or
MediaPlayer.Equalizer.createFromPreset(int)}.
It is possible to apply new equalizer settings to a media player whether the media
player is currently playing media or not.
Invoking this method will immediately apply the new equalizer settings to the audio
output of the currently playing media if there is any.
If there is no currently playing media, the new equalizer settings will be applied
later if and when new media is played.
Equalizer settings will automatically be applied to subsequently played media.
To disable the equalizer for a media player invoke this method passing null.public boolean addSlave(int type,
android.net.Uri uri,
boolean select)
type - see Media.Slave.Typeuri - a valid RFC 2396 Uripublic boolean addSlave(int type,
java.lang.String path,
boolean select)
type - see Media.Slave.Typepath - a local pathpublic void setRate(float rate)
rate - public float getRate()
public boolean isPlaying()
public boolean isSeekable()
public void pause()
public int getPlayerState()
public int getVolume()
public int setVolume(int volume)
volume: - Volume level passed as integerpublic long getTime()
public long setTime(long time)
time: - Time in ms.public float getPosition()
public void setPosition(float pos)
pos: - movie position.public long getLength()
public int getTitle()
public void setTitle(int title)
public int getChapter()
public int previousChapter()
public int nextChapter()
public void setChapter(int chapter)
public void navigate(int navigate)
public void setEventListener(MediaPlayer.EventListener listener)
protected MediaPlayer.Event onEventNative(int eventType, long arg1, long arg2, float argf1)
eventType - event typearg1 - first argumentarg2 - second argumentargf1 - first float argumentprotected void onReleaseNative()
public boolean canDoPassthrough()
public boolean isReleased()
public final boolean retain()
public final void release()
protected void finalize()
finalize in class java.lang.Objectprotected void setEventListener(VLCEvent.Listener<T> listener)
listener - see VLCEvent.Listenerprotected void setEventListener(VLCEvent.Listener<T> listener, android.os.Handler handler)
listener - see VLCEvent.Listenerhandler - Handler in which events are sent. If null, a handler will be created running on the main thread