Class APSMediaPlayer

java.lang.Object
com.appscend.hub.KRHub
com.appscend.media.APSMediaPlayer
All Implemented Interfaces:
APSMediaEventStateListener, APSMediaEventTimeoutListener, VolumeChangedInterface

The APSMediaPlayer handles playback and rendering of APSMediaUnits and APSMediaOverlays.
  • Field Details

    • kAPSMediaPlayerOverlayControllersGroup

      public static final String kAPSMediaPlayerOverlayControllersGroup
      The group name that overlay controllers must use when registering with the player.
      See Also:
    • kAPSMediaPlayerFrameworkExtensionsGroup

      public static final String kAPSMediaPlayerFrameworkExtensionsGroup
      See Also:
    • kAPSMediaPlayerDRMPluginsGroup

      public static final String kAPSMediaPlayerDRMPluginsGroup
      See Also:
    • APSMoviePlayerWasTappedNotification

      public static final String APSMoviePlayerWasTappedNotification
      Posted when the user taps on the media player surface
      See Also:
    • APSMoviePlayerControlsDisplayedNotification

      public static final String APSMoviePlayerControlsDisplayedNotification
      Posted when the video controls bar becomes visible
      See Also:
    • APSMoviePlayerControlsHiddenNotification

      public static final String APSMoviePlayerControlsHiddenNotification
      Posted when the video controls bar becomes hidden
      See Also:
    • APSMoviePlayerStatusChangedNotification

      public static final String APSMoviePlayerStatusChangedNotification
      Posted when the media player playback state has changed. You can immediately get the new state using the playbackState method of the APSMediaPlayer instance.
      See Also:
    • _currentUnit

      public APSMediaUnit _currentUnit
    • handlerThread

      public final android.os.HandlerThread handlerThread
  • Method Details

    • isProcessing

      public boolean isProcessing()
      Returns a Boolean value specifing if the player is currently rendering a playlist of units (read-only).
    • getInstance

      public static APSMediaPlayer getInstance()
      Returns the singleton APSMediaPlayer instance, creating it if necessary.
      Returns:
      The shared APSMediaPlayer instance
    • instanceIfInitialized

      public static APSMediaPlayer instanceIfInitialized()
      The live player, or null before the first getInstance() and after finish(); never creates one.
    • getActivity

      public android.app.Activity getActivity()
      Returns a reference to the Activity the player was initialized with.
      Returns:
      a reference to the Activity the player was initialized with.
    • getHandler

      public android.os.Handler getHandler()
      Returns a reference to a Handler for posting tasks to the UI thread.
      Returns:
      a Handler reference
    • controlsOverlay

      public APSMediaOverlay controlsOverlay()
      Generates an APSMediaOverlay object for displaying the built-in controls on screen, based on the settings of the unit.
      Returns:
      a fully configured controls APSMediaOverlay object.
    • userPinched

      public void userPinched(float scale)
      Handle a pinch action on the player view, toggling full screen mode on.
      Parameters:
      scale - the scale at which the pinch gesture was performed
    • isFullscreen

      public boolean isFullscreen()
      Returns a boolean value specifing if the player is currently in fullscreen (read-only).
    • toggleFullscreen

      public void toggleFullscreen()
      Toggle the current fullscreen status.
    • enterFullscreen

      public void enterFullscreen()
    • setInlineModeParent

      public void setInlineModeParent(android.view.ViewGroup parent)
    • exitFullscreen

      public void exitFullscreen()
      Make the player exit full-screen mode
    • init

      public void init(android.app.Activity activity, boolean statusBarVisible)
      Initialize the Veeplay SDK. This should be done as early as possible in the Activity lifecycle. Init should be always called when starting the application or if finish() was previously called and the player should be reused.
      Parameters:
      activity - the Activity the player is bound to
      statusBarVisible - whether the height of the OS status bar should be taken into account when layouting
    • detachView

      public static void detachView(android.view.ViewGroup parent, android.view.View view)
      Removes an overlay view, clearing its Animation first: removed with one set (fillAfter keeps it), it stays in the parent's mDisappearingChildren.
    • playerTapped

      public void playerTapped()
      Signals to that the player view was tapped (for example for hiding the on-screen controls)
    • showControls

      public void showControls()
    • hideControls

      public void hideControls()
    • playlistSnapshot

      public ArrayList<APSMediaEvent> playlistSnapshot()
      A copy of the playlist taken under its lock.
    • log_message

      public static void log_message(String message)
    • log

      public void log(String message)
      Posts a message to LogCat
      Parameters:
      message - The message to be posted
    • trackforEvent

      public void trackforEvent(ArrayList<String> urls, String event, APSMediaTrackingEvents.MediaEventType type, APSMediaEvent sourceEvent)
    • trackforEvent

      public void trackforEvent(ArrayList<String> urls, String event, APSMediaTrackingEvents.MediaEventType type, APSMediaEvent sourceEvent, boolean emitEvent)
    • trackforEvent

      public void trackforEvent(ArrayList<String> urls, String event, APSMediaTrackingEvents.MediaEventType type, APSMediaEvent sourceEvent, boolean emitEvent, android.os.Bundle additionalInfo)
      Sends tracking information to one or more servers. All specified URLs will be requested via GET. See APSMediaTrackingEventsAPSMediaTrackingEvents for a list of supported event types.
      Parameters:
      urls - An array of String objects that should be pinged.
      event - A descriptive text of the events.
      type - The tracked event type. See APSMediaTrackingEvents.
      sourceEvent - The APSMediaUnit or APSMediaOverlay that triggered this event
    • getCurrentPlayingUrl

      public String getCurrentPlayingUrl()
      Returns:
      The URL currently being played by the player
    • shouldAutoplay

      public boolean shouldAutoplay()
      Checks if currentUnit is not null
      Returns:
      _currentUnit.shouldAutoplay if currentUnit in not null, else returns true
    • currentUnit

      public APSMediaUnit currentUnit()
      Returns a copy of the currently playing media unit.
      Returns:
      An APSMediaUnit object representing the current unit.
    • openURL

      public boolean openURL(String url)
      Instructs the player that a new URL needs to be interpreted and executed. This method will first ask the actionDelegate to respond to the given URL. If the actionDelegate declines to respond and the URL has a web scheme such as ('http:// or 'https://') then an in-app web browser window will be displayed modally.
      Parameters:
      url - The URL that needs to be loaded.
    • performPostTapAction

      public void performPostTapAction()
      Call this method in the onActivityResult callback of the activity linked to the player. The resultCode received when returning from the Veeso Web Browser is always 999
    • playMediaUnits

      public void playMediaUnits(ArrayList<APSMediaEvent> mediaUnits)
      Sets and begins playback of an array of media units.
      Parameters:
      mediaUnits - An array of APSMediaUnit objects.
    • playAlreadySetMediaUnits

      public void playAlreadySetMediaUnits()
    • setSize

      public void setSize(int width, int height)
      Sets the size of the main player container.
      Parameters:
      width - in pixels
      height - in pixels
    • getSize

      public Size getSize()
    • viewController

      public android.view.ViewGroup viewController()
      The container View of the player.
    • player

      public IVeeplayRenderer player()
      All Veeplay renderers (MediaPlayer, ExoPlayer, GoogleCast or any custom renderer) implement the common interface IVeeplayRenderer
      Returns:
      a reference to the currently active renderer
    • playbackStateChanged

      public void playbackStateChanged(APSMediaPlayer.MPMoviePlaybackState newState, boolean track)
    • playbackStateChanged

      public void playbackStateChanged(APSMediaPlayer.MPMoviePlaybackState newState, boolean track, android.os.Bundle additionalInfo)
      Method for transitioning the player between various playback states (paused / playing / seeking, for example)
      Parameters:
      newState - the new playback state the player is transitioning into
      track - whether to send tracking requests to relevant ad-servers or not.
    • playbackState

      public APSMediaPlayer.MPMoviePlaybackState playbackState()
      Returns the current unit's playback state.
      Returns:
      The current playback state.
    • pause

      public void pause()
      Pauses playback of the current unit.
    • resumePlay

      public void resumePlay()
      Restarts playback
    • isPaused

      public boolean isPaused()
      Returns:
      true if the playback is currently paused, false otherwise
    • play

      public void play() throws LicenseInvalidException, RootedPhoneException
      Starts playback of the current unit.
      Throws:
      LicenseInvalidException
      RootedPhoneException
    • stop

      public void stop()
      Stops playback of the current unit.
    • currentPlaybackTime

      public int currentPlaybackTime()
      Returns the current playback time.
      Returns:
      The current playback time.
    • contentPlaybackTime

      public int contentPlaybackTime()
      The content position in ms, never the IMA ad's.
    • playableDuration

      public int playableDuration(int duration)
      Returns the current unit's video clip playable duration (the time interval that has already buffered and is ready for playback).
      Parameters:
      duration - - if the current video is shown through an overlay, this parameter will be multiplied by the result of the playableDuration method invoked on the overlay controller. Can be 0 in other cases;
      Returns:
      The video playable duration.
    • seekTo

      public void seekTo(int pos)
      Sets the current playback time.
      Parameters:
      pos - The playback time to be set in ms.
    • duration

      public int duration()
      Returns the current unit's video clip total duration.
      Returns:
      The video total duration.
    • contentDuration

      public int contentDuration()
      The content duration in ms, never the IMA ad's.
    • isPlaying

      public boolean isPlaying()
      Returns a Boolean value specifing if the player is currently playing a playlist of units (read-only).
    • movieSourceTypeIsLiveStream

      public boolean movieSourceTypeIsLiveStream()
    • skip

      public void skip()
      Proceeds to the next unit in the playlist and sends a skip event.
    • back

      public void back()
      Proceeds to the previous unit in the playlist .
    • loadStatePlayable

      public void loadStatePlayable()
      Once the active renderer has started playback, this method handles the triggering of the correct tracking events, as well as starting the internal state timer.
    • unitFinished

      public void unitFinished(APSMediaPlayer.MPMovieFinishReason reason)
      Handles the tear-down of the currently playing unit when it finishes (either because of unit completion, or because an error has occured or the unit is being skipped). Progress to the next unit is triggered automatically.
      Parameters:
      reason - the reason the unit is being teared down
    • lastContentDuration

      public int lastContentDuration()
      The duration in ms of the last content unit whose duration was known, kept after it finished.
    • volumeChanged

      public void volumeChanged(int volume)
      Detects changes in the current system audio volume and triggers any relevant VAST events.
      Specified by:
      volumeChanged in interface VolumeChangedInterface
      Parameters:
      volume - the current audio volume value
    • finish

      public void finish()
      Tears down all player resources, causing any currently playing units to stop and any tracking events to be issued. Once finish is called, the player should be re-initialized before further use.
    • takeImaSlot

      public void takeImaSlot(APSMediaEvent event)
      A pre- or postroll takes the IMA slot when it triggers; playlist breaks are already sequential.
    • hasImaSuccessor

      public boolean hasImaSuccessor(APSImaAdBreak imaAdBreak)
      Whether a finishing midroll has a queued IMA break due at the held content time to hand its paused content to.
    • imaBreakFinished

      public boolean imaBreakFinished(APSImaAdBreak imaAdBreak, @Nullable APSImaAdBreak.ContentHold hold)
      Main thread: frees a finished break's IMA slot, or hands it with the paused content to a queued same-time break; true if handed over.
    • imaBreakScheduler

      public ImaBreakScheduler imaBreakScheduler()
    • next

      public void next()
      Proceeds to the next unit in the playlist and sends an exit event.
    • step

      public void step()
      Silently proceeds to the next unit in the playlist. Used in cases such as midroll adbreaks triggering.
    • resetDisplayedOverlays

      public void resetDisplayedOverlays()
      Repositions all currently displayed overlays
    • orientationWillChange

      public void orientationWillChange()
      Signals to the player that the orientation of the device is changing
    • showHud

      public void showHud()
      Shows the player "loading" activity indicator.
    • hideHud

      public void hideHud()
      Hides the player "loading" activity indicator.
    • isStreamingUrl

      public boolean isStreamingUrl(String url)
      Method for determining if an URL represents a stream or not
      Parameters:
      url - the url to be used for determination
    • setYouTubeApiKey

      @Deprecated public void setYouTubeApiKey(String apiKey)
      Deprecated.
      YouTube units are skipped.
      No longer used: YouTube units are not supported.
      Parameters:
      apiKey - ignored
    • getYoutubeApiKey

      @Deprecated public String getYoutubeApiKey()
      Deprecated.
      YouTube units are skipped.
      Returns:
      The value passed to setYouTubeApiKey(String)
    • addTrackingEventListener

      public void addTrackingEventListener(APSMediaPlayerTrackingEventListener listener)
      Registers an event listener for receiving player events.
      Parameters:
      listener - - An instance of a class implementing the APSMediaPlayerTrackingEventListener interface
    • removeTrackingEventListener

      public void removeTrackingEventListener(APSMediaPlayerTrackingEventListener listener)
      Removes a registered event listener.
      Parameters:
      listener - - An instance of a class implementing the APSMediaPlayerTrackingEventListener interface
    • removeAllTrackingEventListeners

      public void removeAllTrackingEventListeners()
      Removes all currently registered listeners.
    • getOverlayContainer

      public android.widget.RelativeLayout getOverlayContainer()
      Returns:
      a reference to the RelativeLayout containing the overlays
    • emitEvent

      public void emitEvent(ArrayList<String> urls, String event, APSMediaTrackingEvents.MediaEventType type, android.os.Bundle additionalInfo, APSMediaEvent sourceEvent)
      Sends an APSMediaTrackingEvent to all registered listeners
      Parameters:
      urls - any associated tracking URLs
      event - the VAST string name of the event
      type - the APSMediaTrackingEvent.MediaEventType value for the event to notify
      additionalInfo - a collection of additional information to relay (for example the current playback time for a progress event)
    • onEventStateChanged

      public void onEventStateChanged(APSMediaEvent event, APSMediaEvent.APSMediaEventState newEventState)
      A listener for the current state of the events in the current unit. Detects preloaded events and queues their triggering.
      Specified by:
      onEventStateChanged in interface APSMediaEventStateListener
      Parameters:
      event - the event that has changed state
      newEventState - the state the event has transitioned to
    • onEventTimeout

      public void onEventTimeout(APSMediaEvent event)
      A handler for APSMediaEvents that timeout during their preloading
      Specified by:
      onEventTimeout in interface APSMediaEventTimeoutListener
      Parameters:
      event - the event that has encountered the timeout
    • replaceCurrentUnitWithUnits

      public void replaceCurrentUnitWithUnits(ArrayList<APSMediaUnit> units)
      Replaces the currently playing APSMediaUnit with a collection of media units. Useful for unpacking the ad breaks inside of a MediaUnit into a series of playable APSMediaUnits.
      Parameters:
      units - an ArrayList of units to replace the current unit with.
    • insertMediaUnits

      public void insertMediaUnits(ArrayList<APSMediaUnit> mediaUnits)
      Inserts new media units after the current one, in the current playlist.
      Parameters:
      mediaUnits - An array of APSMediaUnit objects to be inserted into the playlist after the current unit.
    • setMediaUnits

      public void setMediaUnits(ArrayList<APSMediaEvent> mediaUnits)
      Sets new units to the playlist, clearing any old ones.
      Parameters:
      mediaUnits - An array of APSMediaUnit objects to create a new playlist.
    • addOverlays

      public void addOverlays(ArrayList<APSMediaOverlay> overlays)
      Enqueues a series of overlays to be triggered in the current media unit.
      Parameters:
      overlays - the overlays to be inserted into the queue
    • setSecureSurfaceView

      public void setSecureSurfaceView(boolean is_secure)
      Method for preventing the player SurfaceView from being captured in a screenshot or on unsecure screens. Defaults to true. This method should be called before calling init()
      Parameters:
      is_secure - use true in order to secure the SurfaceView
    • isSecureSurfaceView

      public boolean isSecureSurfaceView()
      Check if the surface view is secured from capture
      Returns:
      true if the surface view is running in protected mode
    • setPlayableDuration

      public void setPlayableDuration(int duration)
      Method for setting the currently buffered duration
      Parameters:
      duration - the currently playable duration
    • getMainViewWidth

      public int getMainViewWidth()
      Returns:
      the current width of the main view container
    • getMainViewHeight

      public int getMainViewHeight()
      Returns:
      the current height of the main view container
    • playVideo

      public void playVideo(String url)
      With a currently running content unit, start playback of another stream
      Parameters:
      url - the stream URL
    • computeSurfaceSize

      public void computeSurfaceSize()
      Recalculate the rendering surface size
    • onActivityPaused

      public void onActivityPaused()
      Signals that the bound activity has entered the "paused" state
    • onActivityResumed

      public void onActivityResumed()
      Signals that the bound activity has entered the "resumed" state
    • isActivityPaused

      public boolean isActivityPaused()
      Returns:
      true between onActivityPaused() and onActivityResumed()
    • switchRenderer

      public void switchRenderer()
      Method for switching the current renderer to the next highest priority rendererer. Useful if, for example, a Google Cast device was just connected.
    • setGoogleCastEnabled

      public void setGoogleCastEnabled()
      Enable Google Cast (needs the veeplay-player-android-cast artifact) and its Media Route Button in all content units. Cast starts now if the player is initialized, otherwise in init().
    • isGoogleCastEnabled

      public boolean isGoogleCastEnabled()
      Check if Google Cast support is enabled
    • getPlaylist

      public List<APSMediaEvent> getPlaylist()
      Returns:
      a list of the currently queued media units
    • removeMediaUnits

      public void removeMediaUnits(List<APSMediaEvent> units)
      Removes a list of media units from the playlist
      Parameters:
      units - the list of units to be removed
    • notifySeekFinished

      public void notifySeekFinished()
      Used by renderers to notify that they have completed a seek operation.
    • isSeeking

      public boolean isSeeking()
      Method for checking if the player is currently doing a seek operation
      Returns:
      true if the player is currently seeking
    • getHttpClient

      public okhttp3.OkHttpClient getHttpClient()
      The Veeplay SDK uses OkHttp for sending tracking requests back to the VAST enabled ad-servers.
      Returns:
      The OkHttp client instance used for tracking requests
    • isInitialized

      public static boolean isInitialized()
      Checks if the player was already previously initialized
      Returns:
      true if the player is initialized
    • setSessionCookiesEnabled

      public static void setSessionCookiesEnabled(boolean enabled)
      Turns the session cookie jar for configuration, VAST, tracking and SSAI requests on (the default) or off. While off, those requests neither store nor send cookies, as in 3.1.26. Call it before init(Activity, boolean).
      Parameters:
      enabled - - false to send no cookies on those requests
    • isSessionCookiesEnabled

      public static boolean isSessionCookiesEnabled()
      Returns:
      true while ad and tracking requests use the session cookie jar
    • setMute

      public void setMute(boolean toMute)
      Mutes or unmutes audio playback.
      Parameters:
      toMute - - true for muting audio, false for unmute
    • setVolume

      public void setVolume(float volume)
      Set the current playback audio volume.
      Parameters:
      volume - - a float between 0f and 1f
    • setFullscreenOrientationBehaviour

      public void setFullscreenOrientationBehaviour(APSMediaPlayer.FullscreenOrientationBehaviour fullscreenOrientationBehaviour)
    • isViewable

      public boolean isViewable()
      Checks if the Veeplay container is currently on-screen and un-obscured by any other views
      Returns:
      true or false
    • getCachedPlaybackTime

      public long getCachedPlaybackTime()
    • isCurrentlyInFullscreenOverlayActivity

      public boolean isCurrentlyInFullscreenOverlayActivity()
    • setCurrentlyInFullscreenOverlayActivity

      public void setCurrentlyInFullscreenOverlayActivity(boolean currentlyInFullscreenOverlayActivity)
    • setUserAgent

      public void setUserAgent(String newUserAgent)
    • getUserAgent

      public String getUserAgent()
    • getActionDelegate

      public APSMediaPlayerActionDelegate getActionDelegate()
    • setActionDelegate

      public void setActionDelegate(APSMediaPlayerActionDelegate actionDelegate)
    • isPreferMediaPlayerRenderer

      public boolean isPreferMediaPlayerRenderer()
    • setPreferMediaPlayerRenderer

      public void setPreferMediaPlayerRenderer(boolean preferMediaPlayer)
    • isRestrictRootedAccess

      public boolean isRestrictRootedAccess()
    • setRestrictRootedAccess

      public void setRestrictRootedAccess(boolean restrictRootedAccess)
    • isPreferExoPlayer2

      public boolean isPreferExoPlayer2()
    • setPreferExoPlayer2

      @Deprecated public void setPreferExoPlayer2(boolean preferExoPlayer2)
      Deprecated.
      Both ExoPlayer renderers were replaced by the Media3 renderer; this only raises its priority.
    • getUserLocation

      public android.location.Location getUserLocation()
    • setUserLocation

      public void setUserLocation(android.location.Location userLocation)
    • getAdvertisingIdentifier

      public String getAdvertisingIdentifier()
    • setAdvertisingIdentifier

      public void setAdvertisingIdentifier(String advertisingIdentifier)
    • getAdvertisingIdentifierType

      public String getAdvertisingIdentifierType()
    • setAdvertisingIdentifierType

      public void setAdvertisingIdentifierType(String advertisingIdentifierType)
    • getRegulationInformation

      public RegulationInformation getRegulationInformation()
    • setRegulationInformation

      public void setRegulationInformation(RegulationInformation regulationInformation)
    • getPackageName

      public String getPackageName()
    • isAllowConditionalAds

      public boolean isAllowConditionalAds()
    • setAllowConditionalAds

      public void setAllowConditionalAds(boolean allowConditionalAds)
    • getHttpErrorsListener

      public HTTPErrorsListener getHttpErrorsListener()
    • setHttpErrorsListener

      public void setHttpErrorsListener(HTTPErrorsListener httpErrorsListener)
    • isLeaveFullscreenOnStop

      public boolean isLeaveFullscreenOnStop()
    • setLeaveFullscreenOnStop

      public void setLeaveFullscreenOnStop(boolean leaveFullscreenOnStop)
    • setPlayExternalOverlaysFullscreen

      public void setPlayExternalOverlaysFullscreen(boolean fullscreenMode)
    • isPreferGoogleIma

      public boolean isPreferGoogleIma()
      Check if the Google IMA SDK is enabled (replacing Veeplay VAST parser)
      Returns:
      true if Google IMA is selected
    • setPreferGoogleIma

      public void setPreferGoogleIma(boolean preferGoogleIma)
      Enable or disable Google IMA VAST parser support. Make sure this is called before triggering desired AdBreaks (preferably during the player configuration step).
      Parameters:
      preferGoogleIma - true if Google IMA should be used, false for Veeplay VAST parser
    • fireClickTrackingBeacons

      public void fireClickTrackingBeacons()
      Request the firing of the click tracking beacons in case a non-standard ad overlay is used
    • setAdvancedViewabilityTracking

      public void setAdvancedViewabilityTracking(boolean isEnabled)
      Enable more advanced viewability tracking that takes the entire hierarchy into account
      Parameters:
      isEnabled - - true if the advanced mode should be enabled, false otherwise
    • setAutoPauseWhenNotVisible

      public void setAutoPauseWhenNotVisible(boolean isEnabled)
      Automatically pause playback if the player container is not viewable
      Parameters:
      isEnabled - - true if auto-pause should be enabled, false otherwise
    • isPlayingImaAd

      public boolean isPlayingImaAd()
    • getCurrentImaAdBreak

      public APSImaAdBreak getCurrentImaAdBreak()
    • setCurrentImaAdBreak

      public void setCurrentImaAdBreak(APSImaAdBreak currentImaAdBreak)