Interface JWPlayer


  • public interface JWPlayer
    • Method Detail

      • getVersionCode

        java.lang.String getVersionCode()
        Returns the SDK version.
        Returns:
        The current SDK version.
      • setup

        void setup​(PlayerConfig playerConfig)
        Sets up JW Player with a new PlayerConfig. This can be used to load media and change options (e.g. captions styling) without creating a new instance of the player.
        Parameters:
        playerConfig - The player configuration to use with this JWPlayerView
      • getConfig

        PlayerConfig getConfig()
        Returns the current configuration being used by the player.
        Returns:
        The current configuration.
      • next

        void next()
        Tells JW Player to immediately play the next playlist item.
      • play

        void play()
        Sets the play state of the JW Player. Calling play() while media is playing does nothing.
      • pause

        void pause()
        Pauses playback, changing the state of JW Player from playing to paused. Calling pause() while media is already paused does nothing. Note: When using this method with a non-DVR live stream, the player will appear paused. After this, when play() is called, the stream restarts from the live edge.
      • stop

        void stop()
        Stops the player, returning it to the idle state.
      • seek

        void seek​(double position)
        Seeks the currently playing media to the specified position.
        Parameters:
        position - The position to seek to in seconds from the beginning.
      • setControls

        void setControls​(boolean controls)
        Enable the built-in controls by setting them true, disable the controls by setting them false.
        Parameters:
        controls - whether to enable or disable the controls.
      • playAd

        void playAd​(java.lang.String... tags)
        Used to play an ad right now, which is primarily useful for situations where the built-in ad. schedule of JW Player cannot be used. (e.g. for live streaming or dynamic ads for playlist items).

        Supported for VAST only. Use #playAd(AdClient, String...) if you want to play IMA ads.

        Parameters:
        tags - The ad tags to play.
      • pauseAd

        void pauseAd​(boolean state)
        Used to pause or resume ad playback.
        Parameters:
        state - Set whether or not the ad playback should be paused.
      • setExternalLinkHandler

        void setExternalLinkHandler​(ExternalLinkHandler externalLinkHandler)
        Sets the ExternalLinkHandler, you can use this to override the default behavior of opening the browser when a url is requested.
        Parameters:
        externalLinkHandler - the ExternalLinkHandler to use for opening URLs.
      • openRelatedOverlay

        void openRelatedOverlay()
        Opens the related videos overlay if the current video/playlist has a related feed enabled If the video is still playing it will pause
      • closeRelatedOverlay

        void closeRelatedOverlay()
        Closes the related videos overlay if the current video/playlist has a related feed enabled and is shown
      • openSharingOverlay

        @Deprecated
        void openSharingOverlay()
        Deprecated.
        Opens the sharing plugin. This will also pause content if it is triggered during playback.
      • closeSharingOverlay

        @Deprecated
        void closeSharingOverlay()
        Deprecated.
        Closes the sharing plugin if it is opened. This will resume playback if the sharing overlay was triggered during content.
      • playlistItem

        void playlistItem​(int index)
        Start playback of the playlist item at the specified index.
        Parameters:
        index - The index of a playlist item you wish to play.
      • setCurrentQuality

        void setCurrentQuality​(int index)
        Change the quality level to the provided index. The index must be within the list provided by getQualityLevels().
        Parameters:
        index - Index of the quality level to switch to.
      • setPlaybackRate

        void setPlaybackRate​(double playbackRate)
        Sets playback rate
        Parameters:
        playbackRate - The playback rate to be set
      • setCaptionsRendering

        void setCaptionsRendering​(boolean renderCaptions)
        Sets our captions rendering
        Parameters:
        renderCaptions - set whether or not to disable our captions rendering
      • setCurrentCaptions

        void setCurrentCaptions​(int index)
        Change the visible captions track to the provided index. The index must be within the list provided by getCaptionsList.

        Note an index of 0 always turns the captions Off.

        Parameters:
        index - The index of the caption track to switch to.
      • setCurrentCaptions

        void setCurrentCaptions​(java.lang.String strLocale)
        Change the visible captions track to the RFC 4646 tag provided.
        Parameters:
        strLocale - The string locale in RFC 4646 tag
      • setCurrentCaptions

        void setCurrentCaptions​(java.util.Locale locale)
        Change the visible captions track to the locale provided.
        Parameters:
        locale - The Locale object to defined current caption
      • setCurrentAudioTrack

        void setCurrentAudioTrack​(int index)
        Change the audio track to the provided index. The index must be within the list provided by getAudioTracks().
        Parameters:
        index - Index of the audio track to switch to.
      • setMute

        void setMute()
        Toggles the mute state of the player.
      • setMute

        void setMute​(boolean state)
        Sets the mute state of the player.
        Parameters:
        state - If true, mute the player. If false, unmute the player.
      • setVolume

        void setVolume​(int volume)
        Sets the volume of the player.
        Parameters:
        volume - Volume to use for this player, can be 0 to 100
      • setForceControlsVisibility

        void setForceControlsVisibility​(boolean visible)
        Force controls to be visible, pass false here to revert the controls to their normal behavior
      • setAnalyticsListener

        void setAnalyticsListener​(com.google.android.exoplayer2.analytics.AnalyticsListener listener)
        Sets an AnalyticsListener to receive analytics events.
        Parameters:
        listener - The listener to be added.
      • getState

        PlayerState getState()
        Returns the player's current playback state.
        Returns:
        The player's current playback state.
      • getPosition

        double getPosition()
        Returns the current playback position.
        Returns:
        The current playback position in seconds, or -1 if not available.
      • getAdPosition

        double getAdPosition()
        Returns the current ad playback position.
        Returns:
        The current ad playback position in seconds, or -1 if not available.
      • getDuration

        double getDuration()
        Returns the duration of the current media.
        Returns:
        The current media duration in seconds, or -1 if not available.
      • getPlaylist

        java.util.List<PlaylistItem> getPlaylist()
        Returns the player's current playlist List.
        Returns:
        The player's curent playlist.
      • getPlaylistIndex

        int getPlaylistIndex()
        Returns the index of the currently active item in the playlist.
        Returns:
        The index of the currently active item in the playlist.
      • getPlaylistItem

        PlaylistItem getPlaylistItem​(int index)
        Retrieves the same information as getPlaylist(), but for a single playlist item
        Returns:
        Retrieves the same information as getPlaylist(), but for a single playlist item
      • getBuffer

        int getBuffer()
        Gets the current buffer percentage of the loaded media.
        Returns:
        A percentage (0-100) of the video's current loaded amount
      • getQualityLevels

        java.util.List<QualityLevel> getQualityLevels()
        Returns a list with quality levels from the player.
        Returns:
        List of quality levels from the player.
      • getCurrentQuality

        int getCurrentQuality()
        Returns the index of the currently active quality level.
        Returns:
        The index of the currently active quality level.
      • getPlaybackRate

        double getPlaybackRate()
        Returns current playback rate
        Returns:
        The playback rate
      • getVisualQuality

        VisualQualityEvent getVisualQuality()
        Returns a VisualQuality object containing information about the current quality of a video stream.
        Returns:
        an object containing information about the current quality, or null if the information is not available.
      • getCaptionsList

        java.util.List<Caption> getCaptionsList()
        Returns a List with captions tracks from the player.
        Returns:
        List with captions tracks from the player.
      • getCurrentCaptions

        int getCurrentCaptions()
        Returns the index of the currently active captions track. Note the captions are Off if the index is 0.
        Returns:
        The index of the currently active captions track.
      • getCurrentAudioTrack

        int getCurrentAudioTrack()
        Returns the index of the currently active audio track.
        Returns:
        Index of the currently active audio track.
      • getAudioTracks

        java.util.List<AudioTrack> getAudioTracks()
        Returns a List with audio tracks from the player.
        Returns:
        List with audio tracks from the player.
      • getMute

        boolean getMute()
        Returns whether the player is currently muted or not
        Returns:
        true if the player has been muted, false if it isn't.
      • getVolume

        int getVolume()
        Returns the volume the player is set to
        Returns:
        the volume the player is set to, from 0 to 100
      • getControls

        boolean getControls()
        Returns whether or not the built-in controls are currently enabled
        Returns:
        true if the built-in controls are currently enabled
      • isControlBarVisible

        boolean isControlBarVisible()
        Returns whether or not the built-in control bar is visible.

        Note: this might not give the expected result if you are using a custom CSS skin that alters the behavior of the control bar.

        Returns:
        true if the built-in control bar is visible.
      • setExternalMetadata

        void setExternalMetadata​(java.util.List<ExternalMetadata> externalMetadataList)
        Parameters:
        externalMetadataList -
      • getExoPlayerSettings

        @NonNull
        ExoPlayerSettings getExoPlayerSettings()
        Returns ExoPlayerSettings reference to manage ExoPlayer's settings
        Returns:
        ExoPlayer's settings
      • skipAd

        void skipAd()
        Skips an Ad if one is currently playing and skippable
      • setPlaylistItemCallbackListener

        void setPlaylistItemCallbackListener​(VideoPlayerEvents.PlaylistItemCallbackListener listener)
        Registers a listener to receive a blocking callback before the start of the next playlist item There can only be 1 listener, additional assignments overwrite the previous listener You can set the listener to null to clear to value
      • removePlaylistItemCallbackListener

        void removePlaylistItemCallbackListener()
      • setErrorScreenOkButtonListener

        void setErrorScreenOkButtonListener​(ErrorScreenOkButtonListener errorScreenOkButtonListener)
        Adds a listener for handling clicks on the OK button on the Error screen
      • addListener

        boolean addListener​(@NonNull
                            EventType eventType,
                            @NonNull
                            EventListener eventListener)
        Registers an event listener for a specific player event
        Parameters:
        eventType - The event type to listen to
        eventListener - The listener that will handle the event
        Returns:
        true if adding of listener was successful
      • addListeners

        boolean addListeners​(@NonNull
                             EventListener eventListener,
                             @NonNull
                             EventType... eventTypes)
        Registers an event listener for a list of player events
        Parameters:
        eventListener - The listener that will handle the events
        eventTypes - The event types to listen to
        Returns:
        true if adding of listeners was successful
      • removeListener

        boolean removeListener​(@NonNull
                               EventType eventType,
                               @NonNull
                               EventListener eventListener)
        Deregister an event listener for a specific player event
        Parameters:
        eventType - The event type to stop listening to
        eventListener - The listener that will handle the event
        Returns:
        true if removal of the listener was successful
      • removeListeners

        boolean removeListeners​(@NonNull
                                EventListener eventListener,
                                @NonNull
                                EventType... eventTypes)
        Deregister an event listener for a list of player events
        Parameters:
        eventListener - The listener that will handle the events
        eventTypes - The event types to stop listening to
        Returns:
        true if removal of the listeners was successful
      • removeAllListeners

        void removeAllListeners​(@NonNull
                                EventListener eventListener)
        Deregister an event listener for all player events
        Parameters:
        eventListener - The listener that will be deregistered
      • allowBackgroundAudio

        void allowBackgroundAudio​(boolean allowBackgroundAudio)
        Toggles background audio on/off for this player
        Parameters:
        allowBackgroundAudio - whether or not to allow background audio
      • allowsBackgroundAudio

        boolean allowsBackgroundAudio()
        Returns:
        allowBackgroundAudio value
      • onKeyDown

        boolean onKeyDown​(int keyCode,
                          android.view.KeyEvent event)
        Handles keyDown events and calls the appropriate JWPlayer methods
        Parameters:
        keyCode - The keyCode of the key pressed
      • onKeyUp

        boolean onKeyUp​(int keyCode,
                        android.view.KeyEvent event)
        Handles onKeyUp events and calls the appropriate JWPlayer methods
        Parameters:
        keyCode - The keyCode of the key pressed