Class MediaPlayer

    • Field Detail

      • SURFACE_SCALES_COUNT

        public static final int SURFACE_SCALES_COUNT
    • Constructor Detail

      • MediaPlayer

        public MediaPlayer​(ILibVLC ILibVLC)
        Create an empty MediaPlayer
        Parameters:
        ILibVLC - a valid libVLC
      • MediaPlayer

        public MediaPlayer​(@NonNull
                           IMedia media)
        Create a MediaPlayer from a Media
        Parameters:
        media - a valid Media object
    • Method Detail

      • getVLCVout

        @NonNull
        public IVLCVout getVLCVout()
        Get the IVLCVout helper.
      • attachViews

        public 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 displayed
        dm - Optional DisplayManager to help switch between renderers, primary and secondary displays
        subtitles - Whether you wish to show subtitles
        textureView - If true, VLCVideoLayout will use a TextureView instead of a SurfaceView
      • detachViews

        public void detachViews()
        Detach the video layout
      • updateVideoSurfaces

        public void updateVideoSurfaces()
        Update the video surfaces, either to switch from one to another or to resize it
      • setVideoScale

        public void setVideoScale​(@NonNull
                                  MediaPlayer.ScaleType type)
        Set the video scale type, by default, scaletype is set to ScaleType.SURFACE_BEST_FIT
      • setMedia

        public void setMedia​(@Nullable
                             IMedia media)
        Set a Media
        Parameters:
        media - a valid Media object
      • setRenderer

        public int setRenderer​(@Nullable
                               RendererItem item)
        Set a renderer
        Parameters:
        item - RendererItem. if null VLC play on default output
      • hasMedia

        public boolean hasMedia()
        Is a media in use by this MediaPlayer
        Returns:
        true if a media is set
      • getMedia

        @Nullable
        public IMedia getMedia()
        Get the Media used by this MediaPlayer. This Media should be released with IVLCObject.release().
      • play

        public void play()
        Play the media
      • playAsset

        public void playAsset​(@NonNull
                              Context context,
                              @NonNull
                              String assetFilename)
                       throws IOException
        Load an asset and starts playback
        Parameters:
        context - An application context, mandatory to access assets
        assetFilename - relative path of the asset in app assets folder
        Throws:
        IOException
      • play

        public void play​(@NonNull
                         String path)
        Play a media via its mrl
        Parameters:
        path - Path of the media file to play
      • play

        public void play​(@NonNull
                         Uri uri)
        Play a media via its Uri
        Parameters:
        uri - Uri of the media to play
      • play

        public void play​(@NonNull
                         IMedia media)
        Starts playback from an already prepared Media
        Parameters:
        media - The IMedia to play
      • stop

        public void stop()
        Stops the playing media
      • setVideoTitleDisplay

        public void setVideoTitleDisplay​(int position,
                                         int timeout)
        Set if, and how, the video title will be shown when media is played
        Parameters:
        position - see MediaPlayer.Position
        timeout -
      • getScale

        public float getScale()
        Get the current video scaling factor
        Returns:
        the currently configured zoom factor, or 0. if the video is set to fit to the output window/drawable automatically.
      • setScale

        public 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. Zero is a special value; it will adjust the video to the output window/drawable (in windowed mode) or the entire screen.
        Parameters:
        scale - the scaling factor, or zero
      • getAspectRatio

        public String getAspectRatio()
        Get current video aspect ratio
        Returns:
        the video aspect ratio or NULL if unspecified
      • setAspectRatio

        public void setAspectRatio​(String aspect)
        Set new video aspect ratio.
        Parameters:
        aspect - new video aspect-ratio or NULL to reset to default
      • updateViewpoint

        public boolean updateViewpoint​(float yaw,
                                       float pitch,
                                       float roll,
                                       float fov,
                                       boolean absolute)
        Update the video viewpoint information
        Parameters:
        yaw - View point yaw in degrees
        pitch - View point pitch in degrees
        roll - View point roll in degrees
        fov - Field of view in degrees (default 80.0f)
        absolute - if true replace the old viewpoint with the new one. If false, increase/decrease it.
        Returns:
        true on success.
      • setAudioOutput

        public boolean setAudioOutput​(String aout)
        Selects an audio output module. Any change will take effect only after playback is stopped and restarted. Audio output cannot be changed while playing. By default, the "android_audiotrack" is selected. Starting Android 21, passthrough is enabled for encodings supported by the device/audio system. Calling this method will disable the encoding detection.
        Returns:
        true on success.
      • setAudioDigitalOutputEnabled

        public boolean setAudioDigitalOutputEnabled​(boolean enabled)
        Enable or disable Digital Output Works only with AudioTrack AudioOutput. If setAudioOutputDevice(java.lang.String) was previously called, this method won't have any effects.
        Parameters:
        enabled - true to enable Digital Output
        Returns:
        true on success
      • forceAudioDigitalEncodings

        public boolean forceAudioDigitalEncodings​(int[] encodings)
        Parameters:
        encodings - list of encodings to play via passthrough (see AudioFormat.ENCODING_*), null to don't force any.
        Returns:
        true on success
      • setAudioOutputDevice

        public 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 by ENCODING_FLAGS_MASK. This extra value is a long that contains binary-shifted AudioFormat.ENCODING_* values. Calling this method will disable the encoding detection (see setAudioOutput(java.lang.String) and setAudioDigitalOutputEnabled(boolean)).
        Returns:
        true on success.
      • getTitles

        public MediaPlayer.Title[] getTitles()
        Get the full description of available titles.
        Returns:
        the list of titles
      • getChapters

        public MediaPlayer.Chapter[] getChapters​(int title)
        Get the full description of available chapters.
        Parameters:
        title - index of the title (if -1, use the current title)
        Returns:
        the list of Chapters for the title
      • getVideoTracksCount

        public int getVideoTracksCount()
        Get the number of available video tracks.
      • getVideoTrack

        public int getVideoTrack()
        Get the current video track.
        Returns:
        the video track ID or -1 if no active input
      • setVideoTrack

        public boolean setVideoTrack​(int index)
        Set the video track.
        Returns:
        true on success.
      • setVideoTrackEnabled

        public void setVideoTrackEnabled​(boolean enabled)
        Set the enabled state of the video track
        Parameters:
        enabled -
      • getCurrentVideoTrack

        public IMedia.VideoTrack getCurrentVideoTrack()
        Get the current video track
      • getAudioTracksCount

        public int getAudioTracksCount()
        Get the number of available audio tracks.
      • getAudioTrack

        public int getAudioTrack()
        Get the current audio track.
        Returns:
        the audio track ID or -1 if no active input
      • setAudioTrack

        public boolean setAudioTrack​(int index)
        Set the audio track.
        Returns:
        true on success.
      • getAudioDelay

        public long getAudioDelay()
        Get the current audio delay.
        Returns:
        delay in microseconds.
      • setAudioDelay

        public 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.
        Returns:
        true on success.
      • getSpuTracksCount

        public int getSpuTracksCount()
        Get the number of available spu (subtitle) tracks.
      • getSpuTrack

        public int getSpuTrack()
        Get the current spu (subtitle) track.
        Returns:
        the spu (subtitle) track ID or -1 if no active input
      • setSpuTrack

        public boolean setSpuTrack​(int index)
        Set the spu (subtitle) track.
        Returns:
        true on success.
      • getSpuDelay

        public long getSpuDelay()
        Get the current spu (subtitle) delay.
        Returns:
        delay in microseconds.
      • setSpuDelay

        public 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.
        Returns:
        true on success.
      • setEqualizer

        public boolean setEqualizer​(MediaPlayer.Equalizer equalizer)
        Apply new equalizer settings to a media player. The equalizer is first created by invoking 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.
        Returns:
        true on success.
      • addSlave

        public boolean addSlave​(int type,
                                Uri uri,
                                boolean select)
        Add a slave (or subtitle) to the current media player.
        Parameters:
        type - see IMedia.Slave.Type
        uri - a valid RFC 2396 Uri
        Returns:
        true on success.
      • record

        public boolean record​(String directory)
        Start/stop recording
        Parameters:
        directory - path of the recording directory or null to stop recording
        Returns:
        true on success.
      • addSlave

        public boolean addSlave​(int type,
                                String path,
                                boolean select)
        Add a slave (or subtitle) to the current media player.
        Parameters:
        type - see IMedia.Slave.Type
        path - a local path
        Returns:
        true on success.
      • setRate

        public void setRate​(float rate)
        Sets the speed of playback (1 being normal speed, 2 being twice as fast)
        Parameters:
        rate -
      • getRate

        public float getRate()
        Get the current playback speed
      • isPlaying

        public boolean isPlaying()
        Returns true if any media is playing
      • isSeekable

        public boolean isSeekable()
        Returns true if any media is seekable
      • pause

        public void pause()
        Pauses any playing media
      • getPlayerState

        public int getPlayerState()
        Get player state.
      • getVolume

        public int getVolume()
        Gets volume as integer
      • setVolume

        public int setVolume​(int volume)
        Sets volume as integer
        Parameters:
        volume - : Volume level passed as integer
      • getTime

        public long getTime()
        Gets the current movie time (in ms).
        Returns:
        the movie time (in ms), or -1 if there is no media.
      • setTime

        public 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
        Returns:
        the movie time (in ms), or -1 if there is no media.
      • setTime

        public long setTime​(long time)
      • getPosition

        public float getPosition()
        Gets the movie position.
        Returns:
        the movie position, or -1 for any error.
      • setPosition

        public void setPosition​(float pos,
                                boolean fast)
        Sets the movie position.
        Parameters:
        pos - : movie position.
        fast - : Prefer fast seeking or precise seeking
      • setPosition

        public void setPosition​(float pos)
      • getLength

        public long getLength()
        Gets current movie's length in ms.
        Returns:
        the movie length (in ms), or -1 if there is no media.
      • getTitle

        public int getTitle()
      • setTitle

        public void setTitle​(int title)
      • getChapter

        public int getChapter()
      • previousChapter

        public int previousChapter()
      • nextChapter

        public int nextChapter()
      • setChapter

        public void setChapter​(int chapter)
      • navigate

        public void navigate​(int navigate)
      • onEventNative

        protected MediaPlayer.Event onEventNative​(int eventType,
                                                  long arg1,
                                                  long arg2,
                                                  float argf1,
                                                  @Nullable
                                                  String args1)
        Called when libvlc send events.
        Parameters:
        eventType - event type
        arg1 - first argument
        arg2 - second argument
        argf1 - first float argument
        Returns:
        Event that will be dispatched to listeners
      • onReleaseNative

        protected void onReleaseNative()
        Called when native object is released (refcount is 0). This is where you must release native resources.
      • canDoPassthrough

        public boolean canDoPassthrough()
      • nativeSetTime

        public long nativeSetTime​(long time,
                                  boolean fast)
      • nativeSetPosition

        public void nativeSetPosition​(float pos,
                                      boolean fast)
      • retain

        public final boolean retain()
        Increment internal ref count of the native object.
        Specified by:
        retain in interface IVLCObject<T extends AbstractVLCEvent>
        Returns:
        true if media is retained
      • release

        public final void release()
        Release the native object if ref count is 1. After this call, native calls are not possible anymore. You can still call others methods to retrieve cached values. For example: if you parse, then release a media, you'll still be able to retrieve all Metas or Tracks infos.
        Specified by:
        release in interface IVLCObject<T extends AbstractVLCEvent>
      • finalize

        protected void finalize()
        Overrides:
        finalize in class Object
      • setEventListener

        protected void setEventListener​(AbstractVLCEvent.Listener<T> listener,
                                        Handler handler)
        Set an event listener and an executor Handler
        Parameters:
        listener - see AbstractVLCEvent.Listener
        handler - Handler in which events are sent. If null, a handler will be created running on the main thread
      • getInstance

        public long getInstance()