-
- All Implemented Interfaces:
-
org.videolan.libvlc.interfaces.IVLCObject
public class MediaPlayer extends VLCObject<MediaPlayer.Event>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
MediaPlayer.Event
public interface
MediaPlayer.EventListener
public class
MediaPlayer.Position
public class
MediaPlayer.Navigate
public class
MediaPlayer.Title
public class
MediaPlayer.Chapter
public class
MediaPlayer.TrackDescription
public class
MediaPlayer.Equalizer
public enum
MediaPlayer.ScaleType
-
Field Summary
Fields Modifier and Type Field Description public final static int
SURFACE_SCALES_COUNT
-
Constructor Summary
Constructors Constructor Description MediaPlayer(ILibVLC ILibVLC)
Create an empty MediaPlayer MediaPlayer(IMedia media)
Create a MediaPlayer from a Media
-
Method Summary
Modifier and Type Method Description IVLCVout
getVLCVout()
Get the IVLCVout helper. void
attachViews(@NonNull() VLCVideoLayout surfaceFrame, @Nullable() DisplayManager dm, boolean subtitles, boolean textureView)
Attach a video layout to the player void
detachViews()
Detach the video layout void
updateVideoSurfaces()
Update the video surfaces, either to switch from one to another or to resize it void
setVideoScale(@NonNull() MediaPlayer.ScaleType type)
Set the video scale type, by default, scaletype is set to ScaleType. MediaPlayer.ScaleType
getVideoScale()
Get the current video scale type void
setMedia(@Nullable() IMedia media)
Set a Media int
setRenderer(@Nullable() RendererItem item)
Set a renderer synchronized boolean
hasMedia()
Is a media in use by this MediaPlayer synchronized IMedia
getMedia()
Get the Media used by this MediaPlayer. void
play()
Play the media void
playAsset(@NonNull() Context context, @NonNull() String assetFilename)
Load an asset and starts playback void
play(@NonNull() AssetFileDescriptor afd)
Load an asset and starts playback void
play(@NonNull() String path)
Play a media via its mrl void
play(@NonNull() Uri uri)
Play a media via its Uri void
play(@NonNull() IMedia media)
Starts playback from an already prepared Media void
stop()
Stops the playing media void
setVideoTitleDisplay(int position, int timeout)
Set if, and how, the video title will be shown when media is played float
getScale()
Get the current video scaling factor void
setScale(float scale)
Set the video scaling factorThat is the ratio of the number of pixels on screen to the number of pixels in the originaldecoded video in each dimension. String
getAspectRatio()
Get current video aspect ratio void
setAspectRatio(String aspect)
Set new video aspect ratio. boolean
updateViewpoint(float yaw, float pitch, float roll, float fov, boolean absolute)
Update the video viewpoint information synchronized boolean
setAudioOutput(String aout)
Selects an audio output module.Any change will take effect only after playback is stopped andrestarted. synchronized boolean
setAudioDigitalOutputEnabled(boolean enabled)
Enable or disable Digital OutputWorks only with AudioTrack AudioOutput. synchronized boolean
forceAudioDigitalEncodings(Array<int> encodings)
Convenient method for setAudioOutputDevice void
setUseOrientationFromBounds(Boolean mUseOrientationFromBounds)
Boolean
useOrientationFromBounds()
boolean
setAudioOutputDevice(String id)
Configures an explicit audio output device.Audio output will be moved to the device specified by the device identifier string.Available devices for the "android_audiotrack" module (the default) are"stereo": Up to 2 channels (compat mode)."pcm": Up to 8 channels."encoded": Up to 8 channels, passthrough for every encodings if available."encoded:ENCODING_FLAGS_MASK": passthrough for every encodings specified byENCODING_FLAGS_MASK. Array<MediaPlayer.Title>
getTitles()
Get the full description of available titles. Array<MediaPlayer.Chapter>
getChapters(int title)
Get the full description of available chapters. int
getVideoTracksCount()
Get the number of available video tracks. Array<MediaPlayer.TrackDescription>
getVideoTracks()
Get the list of available video tracks. int
getVideoTrack()
Get the current video track. boolean
setVideoTrack(int index)
Set the video track. void
setVideoTrackEnabled(boolean enabled)
Set the enabled state of the video track IMedia.VideoTrack
getCurrentVideoTrack()
Get the current video track int
getAudioTracksCount()
Get the number of available audio tracks. Array<MediaPlayer.TrackDescription>
getAudioTracks()
Get the list of available audio tracks. int
getAudioTrack()
Get the current audio track. boolean
setAudioTrack(int index)
Set the audio track. long
getAudioDelay()
Get the current audio delay. boolean
setAudioDelay(long delay)
Set current audio delay. int
getSpuTracksCount()
Get the number of available spu (subtitle) tracks. Array<MediaPlayer.TrackDescription>
getSpuTracks()
Get the list of available spu (subtitle) tracks. int
getSpuTrack()
Get the current spu (subtitle) track. boolean
setSpuTrack(int index)
Set the spu (subtitle) track. long
getSpuDelay()
Get the current spu (subtitle) delay. boolean
setSpuDelay(long delay)
Set current spu (subtitle) delay. boolean
setEqualizer(MediaPlayer.Equalizer equalizer)
Apply new equalizer settings to a media player. boolean
addSlave(int type, Uri uri, boolean select)
Add a slave (or subtitle) to the current media player. boolean
record(String directory)
Start/stop recording boolean
addSlave(int type, String path, boolean select)
Add a slave (or subtitle) to the current media player. native void
setRate(float rate)
Sets the speed of playback (1 being normal speed, 2 being twice as fast) native float
getRate()
Get the current playback speed native boolean
isPlaying()
Returns true if any media is playing native boolean
isSeekable()
Returns true if any media is seekable native void
pause()
Pauses any playing media native int
getPlayerState()
Get player state. native int
getVolume()
Gets volume as integer native int
setVolume(int volume)
Sets volume as integer native long
getTime()
Gets the current movie time (in ms). long
setTime(long time, boolean fast)
Sets the movie time (in ms), if any media is being played. long
setTime(long time)
native float
getPosition()
Gets the movie position. void
setPosition(float pos, boolean fast)
Sets the movie position. void
setPosition(float pos)
native long
getLength()
Gets current movie's length in ms. native int
getTitle()
native void
setTitle(int title)
native int
getChapter()
native int
previousChapter()
native int
nextChapter()
native void
setChapter(int chapter)
native void
navigate(int navigate)
synchronized void
setEventListener(MediaPlayer.EventListener listener)
boolean
canDoPassthrough()
native long
nativeSetTime(long time, boolean fast)
native void
nativeSetPosition(float pos, boolean fast)
-
-
Method Detail
-
getVLCVout
@NonNull() IVLCVout getVLCVout()
Get the IVLCVout helper.
-
attachViews
void attachViews(@NonNull() VLCVideoLayout surfaceFrame, @Nullable() DisplayManager dm, boolean subtitles, boolean textureView)
Attach a video layout to the player
- Parameters:
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 android.view.TextureView instead of a android.view.SurfaceView
-
detachViews
void detachViews()
Detach the video layout
-
updateVideoSurfaces
void updateVideoSurfaces()
Update the video surfaces, either to switch from one to another or to resize it
-
setVideoScale
void setVideoScale(@NonNull() MediaPlayer.ScaleType type)
Set the video scale type, by default, scaletype is set to ScaleType.SURFACE_BEST_FIT
-
getVideoScale
@NonNull() MediaPlayer.ScaleType getVideoScale()
Get the current video scale type
-
setMedia
void setMedia(@Nullable() IMedia media)
Set a Media
- Parameters:
media
- a valid Media object
-
setRenderer
int setRenderer(@Nullable() RendererItem item)
Set a renderer
- Parameters:
item
- RendererItem.
-
hasMedia
synchronized boolean hasMedia()
Is a media in use by this MediaPlayer
-
getMedia
@Nullable() synchronized IMedia getMedia()
Get the Media used by this MediaPlayer. This Media should be released with release.
-
play
void play()
Play the media
-
playAsset
void playAsset(@NonNull() Context context, @NonNull() String assetFilename)
Load an asset and starts playback
- Parameters:
context
- An application context, mandatory to access assetsassetFilename
- relative path of the asset in app assets folder
-
play
void play(@NonNull() AssetFileDescriptor afd)
Load an asset and starts playback
- Parameters:
afd
- The AssetFileDescriptor to play
-
play
void play(@NonNull() String path)
Play a media via its mrl
- Parameters:
path
- Path of the media file to play
-
play
void play(@NonNull() Uri uri)
Play a media via its Uri
- Parameters:
uri
- Uri of the media to play
-
play
void play(@NonNull() IMedia media)
Starts playback from an already prepared Media
- Parameters:
media
- The IMedia to play
-
stop
void stop()
Stops the playing media
-
setVideoTitleDisplay
void setVideoTitleDisplay(int position, int timeout)
Set if, and how, the video title will be shown when media is played
- Parameters:
position
- see Position
-
getScale
float getScale()
Get the current video scaling factor
-
setScale
void setScale(float scale)
Set the video scaling factorThat is the ratio of the number of pixels on screen to the number of pixels in the originaldecoded video in each dimension. Zero is a special value; it will adjust the video to theoutput window/drawable (in windowed mode) or the entire screen.
- Parameters:
scale
- the scaling factor, or zero
-
getAspectRatio
String getAspectRatio()
Get current video aspect ratio
-
setAspectRatio
void setAspectRatio(String aspect)
Set new video aspect ratio.
- Parameters:
aspect
- new video aspect-ratio or NULL to reset to default
-
updateViewpoint
boolean updateViewpoint(float yaw, float pitch, float roll, float fov, boolean absolute)
Update the video viewpoint information
- Parameters:
yaw
- View point yaw in degreespitch
- View point pitch in degreesroll
- View point roll in degreesfov
- Field of view in degrees (default 80.absolute
- if true replace the old viewpoint with the new one.
-
setAudioOutput
synchronized boolean setAudioOutput(String aout)
Selects an audio output module.Any change will take effect only after playback is stopped andrestarted. Audio output cannot be changed while playing.By default, the "android_audiotrack" is selected. Starting Android 21, passthrough isenabled for encodings supported by the device/audio system.Calling this method will disable the encoding detection.
-
setAudioDigitalOutputEnabled
synchronized boolean setAudioDigitalOutputEnabled(boolean enabled)
Enable or disable Digital OutputWorks only with AudioTrack AudioOutput.If setAudioOutputDevice was previously called, this method won't have any effects.
- Parameters:
enabled
- true to enable Digital Output
-
forceAudioDigitalEncodings
synchronized boolean forceAudioDigitalEncodings(Array<int> encodings)
Convenient method for setAudioOutputDevice
- Parameters:
encodings
- list of encodings to play via passthrough (see AudioFormat.ENCODING_*),null to don't force any.
-
setUseOrientationFromBounds
void setUseOrientationFromBounds(Boolean mUseOrientationFromBounds)
-
useOrientationFromBounds
Boolean useOrientationFromBounds()
-
setAudioOutputDevice
boolean setAudioOutputDevice(String id)
Configures an explicit audio output device.Audio output will be moved to the device specified by the device identifier string.Available devices for the "android_audiotrack" module (the default) are"stereo": Up to 2 channels (compat mode)."pcm": Up to 8 channels."encoded": Up to 8 channels, passthrough for every encodings if available."encoded:ENCODING_FLAGS_MASK": passthrough for every encodings specified byENCODING_FLAGS_MASK. This extra value is a long that contains binary-shiftedAudioFormat.ENCODING_* values.Calling this method will disable the encoding detection (see setAudioOutput and setAudioDigitalOutputEnabled).
-
getTitles
Array<MediaPlayer.Title> getTitles()
Get the full description of available titles.
-
getChapters
Array<MediaPlayer.Chapter> getChapters(int title)
Get the full description of available chapters.
- Parameters:
title
- index of the title (if -1, use the current title)
-
getVideoTracksCount
int getVideoTracksCount()
Get the number of available video tracks.
-
getVideoTracks
Array<MediaPlayer.TrackDescription> getVideoTracks()
Get the list of available video tracks.
-
getVideoTrack
int getVideoTrack()
Get the current video track.
-
setVideoTrack
boolean setVideoTrack(int index)
Set the video track.
-
setVideoTrackEnabled
void setVideoTrackEnabled(boolean enabled)
Set the enabled state of the video track
-
getCurrentVideoTrack
IMedia.VideoTrack getCurrentVideoTrack()
Get the current video track
-
getAudioTracksCount
int getAudioTracksCount()
Get the number of available audio tracks.
-
getAudioTracks
Array<MediaPlayer.TrackDescription> getAudioTracks()
Get the list of available audio tracks.
-
getAudioTrack
int getAudioTrack()
Get the current audio track.
-
setAudioTrack
boolean setAudioTrack(int index)
Set the audio track.
-
getAudioDelay
long getAudioDelay()
Get the current audio delay.
-
setAudioDelay
boolean setAudioDelay(long delay)
Set current audio delay. The audio delay will be reset to zero each time the media changes.
- Parameters:
delay
- in microseconds.
-
getSpuTracksCount
int getSpuTracksCount()
Get the number of available spu (subtitle) tracks.
-
getSpuTracks
Array<MediaPlayer.TrackDescription> getSpuTracks()
Get the list of available spu (subtitle) tracks.
-
getSpuTrack
int getSpuTrack()
Get the current spu (subtitle) track.
-
setSpuTrack
boolean setSpuTrack(int index)
Set the spu (subtitle) track.
-
getSpuDelay
long getSpuDelay()
Get the current spu (subtitle) delay.
-
setSpuDelay
boolean setSpuDelay(long delay)
Set current spu (subtitle) delay. The spu delay will be reset to zero each time the media changes.
- Parameters:
delay
- in microseconds.
-
setEqualizer
boolean setEqualizer(MediaPlayer.Equalizer equalizer)
Apply new equalizer settings to a media player.The equalizer is first created by invoking create or createFromPreset}.It is possible to apply new equalizer settings to a media player whether the mediaplayer is currently playing media or not.Invoking this method will immediately apply the new equalizer settings to the audiooutput of the currently playing media if there is any.If there is no currently playing media, the new equalizer settings will be appliedlater 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.
-
addSlave
boolean addSlave(int type, Uri uri, boolean select)
Add a slave (or subtitle) to the current media player.
- Parameters:
type
- see IMedia.Slave.Typeuri
- a valid RFC 2396 Uri
-
record
boolean record(String directory)
Start/stop recording
- Parameters:
directory
- path of the recording directory or null to stoprecording
-
addSlave
boolean addSlave(int type, String path, boolean select)
Add a slave (or subtitle) to the current media player.
- Parameters:
type
- see IMedia.Slave.Typepath
- a local path
-
setRate
native void setRate(float rate)
Sets the speed of playback (1 being normal speed, 2 being twice as fast)
-
getRate
native float getRate()
Get the current playback speed
-
isPlaying
native boolean isPlaying()
Returns true if any media is playing
-
isSeekable
native boolean isSeekable()
Returns true if any media is seekable
-
pause
native void pause()
Pauses any playing media
-
getPlayerState
native int getPlayerState()
Get player state.
-
getVolume
native int getVolume()
Gets volume as integer
-
setVolume
native int setVolume(int volume)
Sets volume as integer
- Parameters:
volume
- : Volume level passed as integer
-
getTime
native long getTime()
Gets the current movie time (in ms).
-
setTime
long setTime(long time, boolean fast)
Sets the movie time (in ms), if any media is being played.
- Parameters:
time
- : Time in ms.fast
- : Prefer fast seeking or precise seeking
-
setTime
long setTime(long time)
-
getPosition
native float getPosition()
Gets the movie position.
-
setPosition
void setPosition(float pos, boolean fast)
Sets the movie position.
- Parameters:
pos
- : movie position.fast
- : Prefer fast seeking or precise seeking
-
setPosition
void setPosition(float pos)
-
getLength
native long getLength()
Gets current movie's length in ms.
-
getTitle
native int getTitle()
-
setTitle
native void setTitle(int title)
-
getChapter
native int getChapter()
-
previousChapter
native int previousChapter()
-
nextChapter
native int nextChapter()
-
setChapter
native void setChapter(int chapter)
-
navigate
native void navigate(int navigate)
-
setEventListener
synchronized void setEventListener(MediaPlayer.EventListener listener)
-
canDoPassthrough
boolean canDoPassthrough()
-
nativeSetTime
native long nativeSetTime(long time, boolean fast)
-
nativeSetPosition
native void nativeSetPosition(float pos, boolean fast)
-
-
-
-