-
- 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 classMediaPlayer.Eventpublic interfaceMediaPlayer.EventListenerpublic classMediaPlayer.Positionpublic classMediaPlayer.Navigatepublic classMediaPlayer.Titlepublic classMediaPlayer.Chapterpublic classMediaPlayer.TrackDescriptionpublic classMediaPlayer.Equalizerpublic enumMediaPlayer.ScaleType
-
Field Summary
Fields Modifier and Type Field Description public final static intSURFACE_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 IVLCVoutgetVLCVout()Get the IVLCVout helper. voidattachViews(@NonNull() VLCVideoLayout surfaceFrame, @Nullable() DisplayManager dm, boolean subtitles, boolean textureView)Attach a video layout to the player voiddetachViews()Detach the video layout voidupdateVideoSurfaces()Update the video surfaces, either to switch from one to another or to resize it voidsetVideoScale(@NonNull() MediaPlayer.ScaleType type)Set the video scale type, by default, scaletype is set to ScaleType. MediaPlayer.ScaleTypegetVideoScale()Get the current video scale type voidsetMedia(@Nullable() IMedia media)Set a Media intsetRenderer(@Nullable() RendererItem item)Set a renderer synchronized booleanhasMedia()Is a media in use by this MediaPlayer synchronized IMediagetMedia()Get the Media used by this MediaPlayer. voidplay()Play the media voidplayAsset(@NonNull() Context context, @NonNull() String assetFilename)Load an asset and starts playback voidplay(@NonNull() AssetFileDescriptor afd)Load an asset and starts playback voidplay(@NonNull() String path)Play a media via its mrl voidplay(@NonNull() Uri uri)Play a media via its Uri voidplay(@NonNull() IMedia media)Starts playback from an already prepared Media voidstop()Stops the playing media voidsetVideoTitleDisplay(int position, int timeout)Set if, and how, the video title will be shown when media is played floatgetScale()Get the current video scaling factor voidsetScale(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. StringgetAspectRatio()Get current video aspect ratio voidsetAspectRatio(String aspect)Set new video aspect ratio. booleanupdateViewpoint(float yaw, float pitch, float roll, float fov, boolean absolute)Update the video viewpoint information synchronized booleansetAudioOutput(String aout)Selects an audio output module.Any change will take effect only after playback is stopped andrestarted. synchronized booleansetAudioDigitalOutputEnabled(boolean enabled)Enable or disable Digital OutputWorks only with AudioTrack AudioOutput. synchronized booleanforceAudioDigitalEncodings(Array<int> encodings)Convenient method for setAudioOutputDevice voidsetUseOrientationFromBounds(Boolean mUseOrientationFromBounds)BooleanuseOrientationFromBounds()booleansetAudioOutputDevice(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. intgetVideoTracksCount()Get the number of available video tracks. Array<MediaPlayer.TrackDescription>getVideoTracks()Get the list of available video tracks. intgetVideoTrack()Get the current video track. booleansetVideoTrack(int index)Set the video track. voidsetVideoTrackEnabled(boolean enabled)Set the enabled state of the video track IMedia.VideoTrackgetCurrentVideoTrack()Get the current video track intgetAudioTracksCount()Get the number of available audio tracks. Array<MediaPlayer.TrackDescription>getAudioTracks()Get the list of available audio tracks. intgetAudioTrack()Get the current audio track. booleansetAudioTrack(int index)Set the audio track. longgetAudioDelay()Get the current audio delay. booleansetAudioDelay(long delay)Set current audio delay. intgetSpuTracksCount()Get the number of available spu (subtitle) tracks. Array<MediaPlayer.TrackDescription>getSpuTracks()Get the list of available spu (subtitle) tracks. intgetSpuTrack()Get the current spu (subtitle) track. booleansetSpuTrack(int index)Set the spu (subtitle) track. longgetSpuDelay()Get the current spu (subtitle) delay. booleansetSpuDelay(long delay)Set current spu (subtitle) delay. booleansetEqualizer(MediaPlayer.Equalizer equalizer)Apply new equalizer settings to a media player. intgetTeletext()Gets currently selected teletext page. voidsetTeletext(int page)Select a teletext page.If telexext was not active, activate teletext. booleanaddSlave(int type, Uri uri, boolean select)Add a slave (or subtitle) to the current media player. booleanrecord(String directory)Start/stop recording booleanaddSlave(int type, String path, boolean select)Add a slave (or subtitle) to the current media player. native voidsetRate(float rate)Sets the speed of playback (1 being normal speed, 2 being twice as fast) native floatgetRate()Get the current playback speed native booleanisPlaying()Returns true if any media is playing native booleanisSeekable()Returns true if any media is seekable native voidpause()Pauses any playing media native intgetPlayerState()Get player state. native intgetVolume()Gets volume as integer native intsetVolume(int volume)Sets volume as integer native longgetTime()Gets the current movie time (in ms). longsetTime(long time, boolean fast)Sets the movie time (in ms), if any media is being played. longsetTime(long time)native floatgetPosition()Gets the movie position. voidsetPosition(float pos, boolean fast)Sets the movie position. voidsetPosition(float pos)native longgetLength()Gets current movie's length in ms. native intgetTitle()native voidsetTitle(int title)native intgetChapter()native intpreviousChapter()native intnextChapter()native voidsetChapter(int chapter)native voidnavigate(int navigate)synchronized voidsetEventListener(MediaPlayer.EventListener listener)booleancanDoPassthrough()native longnativeSetTime(long time, boolean fast)native voidnativeSetPosition(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.
-
getTeletext
int getTeletext()
Gets currently selected teletext page.
-
setTeletext
void setTeletext(int page)
Select a teletext page.If telexext was not active, activate teletext.
- Parameters:
page- : page to change to
-
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)
-
-
-
-